Select the types of activity you want to include in your feed.
Remove useDismissable triggering on focus contains
Nested useDismissable's would still trigger if the nested element contains focus, since they're nested. This would trigger an unintentional cascade dismiss.
···9494 cy.get('@inside').should('not.be.visible');
9595});
96969797-it('is dismissed without priority when it has focus', () => {
9898- const Second = () => {
9999- const ref = useRef<HTMLDivElement>(null);
100100- useDismissable(ref, () => {});
101101- return <div ref={ref} />;
102102- };
103103-104104- mount(
105105- <main>
106106- <button className="outside">outside</button>
107107- <Dialog />
108108- <Second />
109109- </main>
110110- );
111111-112112- cy.get('.inside').as('inside').should('be.visible');
113113- // not dismissed with escape press
114114- cy.realPress('Escape');
115115- cy.get('@inside').should('be.visible');
116116- // is dismissed when it has focus
117117- cy.get('@inside').focus();
118118- cy.realPress('Escape');
119119- cy.get('@inside').should('not.be.visible');
120120-});
121121-12297it('is dismissed when focus moves out of it, with focus loss active', () => {
12398 mount(
12499 <main>
+2-8
src/useDismissable.ts
···5656 return;
5757 }
58585959- const active = document.activeElement;
6060- if (
6161- event.code === 'Escape' &&
6262- (hasPriority.current || (active && contains(element, active)))
6363- ) {
5959+ if (event.code === 'Escape' && hasPriority.current) {
6460 // The current dialog can be dismissed by pressing escape if it either has focus
6561 // or it has priority
6662 event.preventDefault();
···72687369 function onClick(event: MouseEvent | TouchEvent) {
7470 const { target } = event;
7575- const active = document.activeElement;
7671 if (event.defaultPrevented) {
7772 return;
7873 } else if (contains(element, target)) {
7974 willLoseFocus = false;
8075 return;
8181- } else if (hasPriority || (active && contains(element, active))) {
7676+ } else if (hasPriority.current) {
8277 // The current dialog can be dismissed by pressing outside of it if it either has
8378 // focus or it has priority
8484- event.preventDefault();
8579 onDismissRef.current();
8680 }
8781 }