mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 17:58:43 -05:00
fix: listbox more menu is broken (#1089)
* fix: make sure portal popover closes correctly * fix: update more actions correctly * fix: get rid of states * chore: update test
This commit is contained in:
@@ -115,8 +115,7 @@ function ActionsToolbar({
|
|||||||
|
|
||||||
const { translator, keyboardNavigation } = useContext(InstanceContext);
|
const { translator, keyboardNavigation } = useContext(InstanceContext);
|
||||||
const [showMoreItems, setShowMoreItems] = useState(false);
|
const [showMoreItems, setShowMoreItems] = useState(false);
|
||||||
const [moreEnabled, setMoreEnabled] = useState(more.enabled);
|
|
||||||
const [moreActions, setMoreActions] = useState(more.actions);
|
|
||||||
const moreRef = useRef();
|
const moreRef = useRef();
|
||||||
const actionsRef = useRef();
|
const actionsRef = useRef();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -131,10 +130,6 @@ function ActionsToolbar({
|
|||||||
|
|
||||||
useEffect(() => () => setShowMoreItems(false), [popover.show]);
|
useEffect(() => () => setShowMoreItems(false), [popover.show]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setMoreEnabled(more.enabled);
|
|
||||||
}, [more.enabled]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!focusHandler) return;
|
if (!focusHandler) return;
|
||||||
|
|
||||||
@@ -150,7 +145,14 @@ function ActionsToolbar({
|
|||||||
focusHandler.on('focus_toolbar_last', focusLast);
|
focusHandler.on('focus_toolbar_last', focusLast);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const newActions = useMemo(() => actions.filter((a) => !a.hidden), [actions]);
|
let moreEnabled = more.enabled;
|
||||||
|
let moreActions = more.actions;
|
||||||
|
const newActions = actions.filter((a) => !a.hidden);
|
||||||
|
if (newActions.length > maxItems) {
|
||||||
|
const newMoreActions = newActions.splice(-(newActions.length - maxItems) - 1);
|
||||||
|
moreEnabled = true;
|
||||||
|
moreActions = [...newMoreActions, ...more.actions];
|
||||||
|
}
|
||||||
|
|
||||||
if (!selections.show && newActions.length === 0) return null;
|
if (!selections.show && newActions.length === 0) return null;
|
||||||
|
|
||||||
@@ -168,12 +170,6 @@ function ActionsToolbar({
|
|||||||
action: () => setShowMoreItems(!showMoreItems),
|
action: () => setShowMoreItems(!showMoreItems),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (newActions.length > maxItems) {
|
|
||||||
const newMoreActions = newActions.splice(-(newActions.length - maxItems) - 1);
|
|
||||||
setMoreEnabled(true);
|
|
||||||
setMoreActions([...newMoreActions, ...more.actions]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const tabCallback =
|
const tabCallback =
|
||||||
// if keyboardNavigation is true, create a callback to handle tabbing from the first/last button in the toolbar that resets focus on the content
|
// if keyboardNavigation is true, create a callback to handle tabbing from the first/last button in the toolbar that resets focus on the content
|
||||||
keyboardNavigation && focusHandler && focusHandler.refocusContent
|
keyboardNavigation && focusHandler && focusHandler.refocusContent
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import useActionState from '../hooks/useActionState';
|
|||||||
|
|
||||||
const PREFIX = 'More';
|
const PREFIX = 'More';
|
||||||
|
|
||||||
|
const ActionsToolbarMoreElement = {
|
||||||
|
className: 'njs-action-toolbar-more',
|
||||||
|
};
|
||||||
|
|
||||||
const classes = {
|
const classes = {
|
||||||
icon: `${PREFIX}-icon`,
|
icon: `${PREFIX}-icon`,
|
||||||
};
|
};
|
||||||
@@ -51,10 +55,12 @@ const More = React.forwardRef(
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
open={show}
|
open={show}
|
||||||
anchorEl={alignTo.current}
|
anchorEl={alignTo.current}
|
||||||
getContentAnchorEl={null}
|
|
||||||
hideBackdrop
|
|
||||||
style={{ pointerEvents: 'none' }}
|
|
||||||
transitionDuration={0}
|
transitionDuration={0}
|
||||||
|
slotProps={{
|
||||||
|
root: {
|
||||||
|
className: ActionsToolbarMoreElement.className,
|
||||||
|
},
|
||||||
|
}}
|
||||||
anchorOrigin={{
|
anchorOrigin={{
|
||||||
vertical: 'bottom',
|
vertical: 'bottom',
|
||||||
horizontal: 'left',
|
horizontal: 'left',
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ function ListBoxWrapper({ app, fieldIdentifier, qId, stateName, element, options
|
|||||||
|
|
||||||
const selections = hasExternalSelectionsApi
|
const selections = hasExternalSelectionsApi
|
||||||
? options.selectionsApi
|
? options.selectionsApi
|
||||||
: useObjectSelections(app, model, elementRef, options)[0];
|
: useObjectSelections(app, model, [elementRef, '.njs-action-toolbar-more'], options)[0];
|
||||||
|
|
||||||
if (!selections || !model) {
|
if (!selections || !model) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -109,7 +109,12 @@ describe('ListBoxPortal', () => {
|
|||||||
};
|
};
|
||||||
const elem = ListBoxPortal({ app, fieldIdentifier, options });
|
const elem = ListBoxPortal({ app, fieldIdentifier, options });
|
||||||
await render(elem);
|
await render(elem);
|
||||||
expect(useObjectSelectionsMock).toHaveBeenCalledWith(app, options.sessionModel, elementRef, options);
|
expect(useObjectSelectionsMock).toHaveBeenCalledWith(
|
||||||
|
app,
|
||||||
|
options.sessionModel,
|
||||||
|
[elementRef, '.njs-action-toolbar-more'],
|
||||||
|
options
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -186,11 +186,11 @@ const getClickOutFuncs = ({ elements, objectSelections, options }) => {
|
|||||||
return {
|
return {
|
||||||
activateClickOut() {
|
activateClickOut() {
|
||||||
document.addEventListener('mousedown', handler);
|
document.addEventListener('mousedown', handler);
|
||||||
options.onSelectionActivated?.();
|
options?.onSelectionActivated?.();
|
||||||
},
|
},
|
||||||
deactivateClickOut() {
|
deactivateClickOut() {
|
||||||
document.removeEventListener('mousedown', handler);
|
document.removeEventListener('mousedown', handler);
|
||||||
options.onSelectionDeactivated?.();
|
options?.onSelectionDeactivated?.();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ const config = ({ format = 'umd', debug = false, file, targetPkg }) => {
|
|||||||
json(),
|
json(),
|
||||||
commonjs(),
|
commonjs(),
|
||||||
babel({
|
babel({
|
||||||
|
babelHelpers: 'bundled',
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
include: [
|
include: [
|
||||||
'/**/apis/conversion/**',
|
'/**/apis/conversion/**',
|
||||||
|
|||||||
Reference in New Issue
Block a user