diff --git a/packages/elements/package.json b/packages/elements/package.json index af08d8748..1d80e8f16 100644 --- a/packages/elements/package.json +++ b/packages/elements/package.json @@ -26,7 +26,7 @@ "deploy": "gh-pages -d example/build" }, "dependencies": { - "@react-aria/focus": "3.3.0", + "@react-aria/focus": "^3.15.0", "@stenajs-webui/core": "18.12.1", "@stenajs-webui/theme": "18.12.1", "classnames": "^2.3.1" diff --git a/packages/elements/src/components/ui/action-menu/UseActionMenuLogic.ts b/packages/elements/src/components/ui/action-menu/UseActionMenuLogic.ts index baf48e106..93687b073 100644 --- a/packages/elements/src/components/ui/action-menu/UseActionMenuLogic.ts +++ b/packages/elements/src/components/ui/action-menu/UseActionMenuLogic.ts @@ -32,12 +32,12 @@ export const useActionMenuLogic = ( case "ArrowDown": case "ArrowRight": event.preventDefault(); - focusManager.focusNext({ wrap: true }); + focusManager?.focusNext({ wrap: true }); break; case "ArrowUp": case "ArrowLeft": event.preventDefault(); - focusManager.focusPrevious({ wrap: true }); + focusManager?.focusPrevious({ wrap: true }); break; case " ": event.preventDefault(); diff --git a/packages/elements/src/components/ui/buttons/menu-button/IconMenuButton.tsx b/packages/elements/src/components/ui/buttons/menu-button/IconMenuButton.tsx index aa09eb262..12aeb7253 100644 --- a/packages/elements/src/components/ui/buttons/menu-button/IconMenuButton.tsx +++ b/packages/elements/src/components/ui/buttons/menu-button/IconMenuButton.tsx @@ -32,6 +32,7 @@ export const IconMenuButton = forwardRef< styles.button, selected && styles.selected, disabled && styles.disabled, + styles.iconOnly, styles[variant], className )} diff --git a/packages/panels/src/components/action-menu-button/ActionMenuButton.tsx b/packages/panels/src/components/action-menu-button/ActionMenuButton.tsx index 1c873a544..3759a32f1 100644 --- a/packages/panels/src/components/action-menu-button/ActionMenuButton.tsx +++ b/packages/panels/src/components/action-menu-button/ActionMenuButton.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import { ReactNode, useMemo, useRef } from "react"; +import { ReactNode, RefObject, useMemo, useRef } from "react"; import { ActionMenu, ActionMenuContext, @@ -34,6 +34,7 @@ export interface ActionMenuButtonProps | typeof SecondaryButton | typeof FlatButton; disableArrow?: boolean; + buttonRef?: RefObject; } export const ActionMenuButton: React.FC = ({ @@ -47,11 +48,13 @@ export const ActionMenuButton: React.FC = ({ menuTop, onClick, disableArrow = false, + buttonRef, ...buttonProps }) => { const [isOpen, open, close, toggle] = useBoolean(false); - const buttonRef = useRef(null); + const fallbackRef = useRef(null); + const ref = buttonRef ?? fallbackRef; const focusManager: TippyPlugin = { name: "focusManager", @@ -83,8 +86,8 @@ export const ActionMenuButton: React.FC = ({ ?.focus(); }, onHide() { - if (buttonRef.current && restoreFocus) { - buttonRef.current.focus(); + if (ref.current && restoreFocus) { + ref.current.focus(); } }, }; @@ -105,7 +108,7 @@ export const ActionMenuButton: React.FC = ({