Skip to content

Commit

Permalink
fix(Popup): close popup when properties panel detaches
Browse files Browse the repository at this point in the history
  • Loading branch information
marstamm committed Jan 22, 2024
1 parent 441d2e4 commit 7defc52
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as focusTrap from 'focus-trap';
import { DragIcon } from './icons';

import { createDragger } from './util/dragger';
import { useEvent } from '../hooks/useEvent';


const noop = () => {};
Expand Down Expand Up @@ -116,6 +117,8 @@ function PopupComponent(props, globalRef) {
return () => focusTrapRef.current && focusTrapRef.current.deactivate();
}, [ popupRef ]);

useEvent('propertiesPanel.detach', onClose);

return createPortal(
<div
aria-label={ title }
Expand Down
43 changes: 43 additions & 0 deletions test/spec/components/Popup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from 'test/TestHelper';

import { Popup } from 'src/components/Popup';
import { EventContext } from '../../../src/context';

insertCoreStyles();

Expand Down Expand Up @@ -145,6 +146,48 @@ describe('<Popup>', function() {
});


it('should close on detach', async function() {

// given
const closeSpy = sinon.spy();

const MockEventBus = (() => {
let callback;

return {
on: (ev, cb) => {
if (ev !== 'propertiesPanel.detach') {
return;
}
callback = cb;
},
off: () => {},
fire: () => {
callback();
}
};
})();


const eventContext = {
eventBus: MockEventBus
};

await act(() => {
render(
<EventContext.Provider value={ eventContext }>
<Popup onClose={ closeSpy }><input name="foo"></input></Popup>
</EventContext.Provider>, { container });
});

// when
MockEventBus.fire('propertiesPanel.detach');

// then
expect(closeSpy).to.have.been.called;
});


it('should close on ESC', async function() {

// given
Expand Down

0 comments on commit 7defc52

Please sign in to comment.