Skip to content

Commit

Permalink
fix(popup-menu): make actual widget keyboard selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Nov 25, 2022
1 parent f78a1a5 commit 9fda6b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
1 change: 1 addition & 0 deletions assets/diagram-js.css
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ marker.djs-dragger tspan {
box-shadow: 0px 2px 10px var(--popup-shadow-color);
padding-top: 12px;
min-width: 120px;
outline: none;
}

.djs-popup-search input {
Expand Down
25 changes: 11 additions & 14 deletions lib/features/popup-menu/PopupMenuComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,17 @@ function PopupMenuWrapper(props) {
onClose();
}, [ onClose ]);

const overlayRef = useRef();

useLayoutEffect(() => {
if (typeof positionGetter !== 'function') {
return;
}

const overlayEl = overlayRef.current;
const position = positionGetter(overlayEl);
const popupEl = popupRef.current;
const position = positionGetter(popupEl);

overlayEl.style.left = `${position.x}px`;
overlayEl.style.top = `${position.y}px`;
}, [ overlayRef.current, positionGetter ]);
popupEl.style.left = `${position.x}px`;
popupEl.style.top = `${position.y}px`;
}, [ popupRef.current, positionGetter ]);

// focus popup initially, on mount
useLayoutEffect(() => {
Expand All @@ -281,15 +279,14 @@ function PopupMenuWrapper(props) {
<div
class="djs-popup-backdrop"
onClick=${ checkClose }
onKeydown=${ onKeydown }
onKeyup=${ onKeyup }
ref=${ popupRef }
tabIndex="-1"
>
<div
class=${ classNames('djs-popup', className) }
ref=${ overlayRef }
style=${ getOverlayStyle(props) }
style=${ getPopupStyle(props) }
onKeydown=${ onKeydown }
onKeyup=${ onKeyup }
ref=${ popupRef }
tabIndex="-1"
>
${children}
</div>
Expand All @@ -299,7 +296,7 @@ function PopupMenuWrapper(props) {

// helpers //////////////////////

function getOverlayStyle(props) {
function getPopupStyle(props) {
return {
transform: `scale(${props.scale})`,
width: `${props.width}px`
Expand Down
2 changes: 1 addition & 1 deletion test/spec/features/popup-menu/PopupMenuComponentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('features/popup-menu - <PopupMenu>', function() {
});

const popupEl = domQuery(
'.djs-popup-backdrop', container
'.djs-popup', container
);

// then
Expand Down

0 comments on commit 9fda6b0

Please sign in to comment.