From 3bc1d0895f84cb248001cce1308127bb01fde28e Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 22 Aug 2025 01:44:55 -0700 Subject: [PATCH] fix(richtext-lexical): toolbar dropdown items are disabled when selecting via double-click (#13544) Fixes https://github.com/payloadcms/payload/issues/13275 by ensuring that toolbar styles are updated on mount. This PR also improves the lexical test suite by adding data attributes that can be targeted more easily --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211110462564657 --- .../toolbars/fixed/client/Toolbar/index.tsx | 6 +- .../toolbars/inline/client/Toolbar/index.tsx | 1 + .../toolbars/shared/ToolbarButton/index.tsx | 11 ++- .../shared/ToolbarDropdown/DropDown.tsx | 8 +++ .../toolbars/shared/ToolbarDropdown/index.tsx | 5 ++ packages/ui/src/elements/Button/index.tsx | 2 + packages/ui/src/elements/Button/types.ts | 1 + .../_LexicalFullyFeatured/e2e.spec.ts | 52 +++++++++++--- test/lexical/collections/utils.ts | 68 ++++++++++++++++++- 9 files changed, 142 insertions(+), 12 deletions(-) diff --git a/packages/richtext-lexical/src/features/toolbars/fixed/client/Toolbar/index.tsx b/packages/richtext-lexical/src/features/toolbars/fixed/client/Toolbar/index.tsx index f4d2a51561..ab16cd5b40 100644 --- a/packages/richtext-lexical/src/features/toolbars/fixed/client/Toolbar/index.tsx +++ b/packages/richtext-lexical/src/features/toolbars/fixed/client/Toolbar/index.tsx @@ -116,7 +116,11 @@ function ToolbarGroupComponent({ ) return ( -
+
{group.type === 'dropdown' && group.items.length ? ( DropdownIcon ? ( {group.type === 'dropdown' && group.items.length ? ( diff --git a/packages/richtext-lexical/src/features/toolbars/shared/ToolbarButton/index.tsx b/packages/richtext-lexical/src/features/toolbars/shared/ToolbarButton/index.tsx index c596e5e414..efd6beea2d 100644 --- a/packages/richtext-lexical/src/features/toolbars/shared/ToolbarButton/index.tsx +++ b/packages/richtext-lexical/src/features/toolbars/shared/ToolbarButton/index.tsx @@ -63,6 +63,9 @@ export const ToolbarButton = ({ const runDeprioritized = useRunDeprioritized() useEffect(() => { + // Run on mount + void runDeprioritized(updateStates) + const listener = () => runDeprioritized(updateStates) const cleanup = mergeRegister(editor.registerUpdateListener(listener)) @@ -99,7 +102,13 @@ export const ToolbarButton = ({ }, []) return ( - ) diff --git a/packages/richtext-lexical/src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx b/packages/richtext-lexical/src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx index bfa2c34eaf..6e64ff36ea 100644 --- a/packages/richtext-lexical/src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx +++ b/packages/richtext-lexical/src/features/toolbars/shared/ToolbarDropdown/DropDown.tsx @@ -21,6 +21,7 @@ export function DropDownItem({ enabled, Icon, item, + itemKey, tooltip, }: { active?: boolean @@ -29,6 +30,7 @@ export function DropDownItem({ enabled?: boolean Icon: React.ReactNode item: ToolbarGroupItem + itemKey: string tooltip?: string }): React.ReactNode { const className = useMemo(() => { @@ -64,6 +66,9 @@ export function DropDownItem({ buttonStyle="none" className={className} disabled={enabled === false} + extraButtonProps={{ + 'data-item-key': itemKey, + }} icon={Icon} iconPosition="left" iconStyle="none" @@ -183,6 +188,7 @@ export function DropDown({ buttonClassName, children, disabled = false, + dropdownKey, Icon, itemsContainerClassNames, label, @@ -192,6 +198,7 @@ export function DropDown({ buttonClassName: string children: ReactNode disabled?: boolean + dropdownKey: string Icon?: React.FC itemsContainerClassNames?: string[] label?: string @@ -262,6 +269,7 @@ export function DropDown({