An open source design system that's fully customizable and agent ready
TypeScript
fix: add hasAutoFocus to Popover/MoreMenu, disable in showcases (#2011)
Cindy Zhangcfdd8e8c0427
diff --git a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuShowcase.tsx b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuShowcase.tsxindex 5c02d3e97f..96ea3d3575 100644--- a/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuShowcase.tsx+++ b/packages/cli/templates/blocks/components/DropdownMenu/DropdownMenuShowcase.tsx@@ -10,6 +10,7 @@ export default function DropdownMenuShowcase() {<XDSDropdownMenuisMenuOpen={isMenuOpen}onOpenChange={setIsMenuOpen}+ hasAutoFocus={false}button={{label: 'Actions'}}items={[{label: 'Edit', onClick: () => {}},diff --git a/packages/cli/templates/blocks/components/DropdownMenuItem/DropdownMenuItemShowcase.tsx b/packages/cli/templates/blocks/components/DropdownMenuItem/DropdownMenuItemShowcase.tsxindex 45ba3bb6f9..c4d3e67a5b 100644--- a/packages/cli/templates/blocks/components/DropdownMenuItem/DropdownMenuItemShowcase.tsx+++ b/packages/cli/templates/blocks/components/DropdownMenuItem/DropdownMenuItemShowcase.tsx@@ -3,21 +3,42 @@import {XDSDropdownMenu, XDSDropdownMenuItem} from '@xds/core/DropdownMenu';const PencilIcon = (props: React.SVGProps<SVGSVGElement>) => (- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" {...props}>+ <svg+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth={1.5}+ strokeLinecap="round"+ strokeLinejoin="round"+ {...props}><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" /><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" /></svg>);const CopyIcon = (props: React.SVGProps<SVGSVGElement>) => (- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" {...props}>+ <svg+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth={1.5}+ strokeLinecap="round"+ strokeLinejoin="round"+ {...props}><rect x="9" y="9" width="13" height="13" rx="2" /><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" /></svg>);const ShareIcon = (props: React.SVGProps<SVGSVGElement>) => (- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" {...props}>+ <svg+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth={1.5}+ strokeLinecap="round"+ strokeLinejoin="round"+ {...props}><circle cx="18" cy="5" r="3" /><circle cx="6" cy="12" r="3" /><circle cx="18" cy="19" r="3" />@@ -27,7 +48,14 @@ const ShareIcon = (props: React.SVGProps<SVGSVGElement>) => ();const TrashIcon = (props: React.SVGProps<SVGSVGElement>) => (- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" {...props}>+ <svg+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth={1.5}+ strokeLinecap="round"+ strokeLinejoin="round"+ {...props}><polyline points="3 6 5 6 21 6" /><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" /></svg>@@ -35,7 +63,11 @@ const TrashIcon = (props: React.SVGProps<SVGSVGElement>) => (export default function DropdownMenuItemShowcase() {return (- <XDSDropdownMenu button={{label: 'Actions'}} isMenuOpen onOpenChange={() => {}}>+ <XDSDropdownMenu+ button={{label: 'Actions'}}+ isMenuOpen+ hasAutoFocus={false}+ onOpenChange={() => {}}><XDSDropdownMenuItemicon={PencilIcon}label="Edit"@@ -48,11 +80,7 @@ export default function DropdownMenuItemShowcase() {description="Create a copy"onClick={() => {}}/>- <XDSDropdownMenuItem- icon={ShareIcon}- label="Share"- onClick={() => {}}- />+ <XDSDropdownMenuItem icon={ShareIcon} label="Share" onClick={() => {}} /><XDSDropdownMenuItemicon={TrashIcon}label="Delete"diff --git a/packages/cli/templates/blocks/components/MoreMenu/MoreMenuShowcase.tsx b/packages/cli/templates/blocks/components/MoreMenu/MoreMenuShowcase.tsxindex 582b22e87a..80eaf101da 100644--- a/packages/cli/templates/blocks/components/MoreMenu/MoreMenuShowcase.tsx+++ b/packages/cli/templates/blocks/components/MoreMenu/MoreMenuShowcase.tsx@@ -10,6 +10,7 @@ export default function MoreMenuShowcase() {<XDSMoreMenuisMenuOpen={isMenuOpen}onOpenChange={setIsMenuOpen}+ hasAutoFocus={false}items={[{label: 'Edit', onClick: () => {}},{label: 'Duplicate', onClick: () => {}},diff --git a/packages/cli/templates/blocks/components/Popover/PopoverShowcase.tsx b/packages/cli/templates/blocks/components/Popover/PopoverShowcase.tsxindex 13501121f0..981955d2e1 100644--- a/packages/cli/templates/blocks/components/Popover/PopoverShowcase.tsx+++ b/packages/cli/templates/blocks/components/Popover/PopoverShowcase.tsx@@ -14,14 +14,19 @@ export default function PopoverShowcase() {<XDSPopoverisOpen={isOpen}onOpenChange={setIsOpen}+ hasAutoFocus={false}placement="below"label="Settings"width={280}content={<XDSVStack gap={3}>- <XDSHeading level={4} tabIndex={0}>Settings</XDSHeading>+ <XDSHeading level={4} tabIndex={0}>+ Settings+ </XDSHeading><XDSDivider />- <XDSText type="body">Notifications, dark mode, and sound preferences.</XDSText>+ <XDSText type="body">+ Notifications, dark mode, and sound preferences.+ </XDSText></XDSVStack>}><XDSButton label="Settings">Settings</XDSButton>diff --git a/packages/core/src/MoreMenu/MoreMenu.doc.mjs b/packages/core/src/MoreMenu/MoreMenu.doc.mjsindex 544a0fee66..59a6b7b858 100644--- a/packages/core/src/MoreMenu/MoreMenu.doc.mjs+++ b/packages/core/src/MoreMenu/MoreMenu.doc.mjs@@ -42,6 +42,12 @@ export const docs = {description: 'Whether the menu trigger is disabled.',default: 'false',},+ {+ name: 'hasAutoFocus',+ type: 'boolean',+ description: 'Whether to auto-focus the first menu item when the menu opens. Set to false for inline showcases or documentation previews.',+ default: 'true',+ },{name: 'children',type: '(item: XDSDropdownMenuItemData) => ReactNode',@@ -112,6 +118,12 @@ export const docsZh = {description: '菜单触发器是否禁用。',default: 'false',},+ {+ name: 'hasAutoFocus',+ type: 'boolean',+ description: '菜单打开时是否自动聚焦第一个菜单项。内联展示或文档预览设为 false。',+ default: 'true',+ },{name: 'children',type: '(item: XDSDropdownMenuItemData) => ReactNode',@@ -161,6 +173,7 @@ export const docsDense = {size: 'Trigger button size.',icon: 'Override default three-dot icon. Accepts any ReactNode.',isDisabled: 'Whether menu trigger disabled.',+ hasAutoFocus: 'Auto-focus first item on open; false for showcases.',children: 'Custom render function for selectable items (not dividers/sections).',xstyle:'StyleX styles for layout customization (margins, positioning, sizing). Must be stylex.create() value.',diff --git a/packages/core/src/MoreMenu/XDSMoreMenu.tsx b/packages/core/src/MoreMenu/XDSMoreMenu.tsxindex 77ccc91436..f620eab3c7 100644--- a/packages/core/src/MoreMenu/XDSMoreMenu.tsx+++ b/packages/core/src/MoreMenu/XDSMoreMenu.tsx@@ -74,6 +74,13 @@ export interface XDSMoreMenuProps {*/onOpenChange?: (isOpen: boolean) => void;+ /**+ * Whether to auto-focus the first menu item when the menu opens.+ * Set to `false` for inline showcases or documentation previews.+ * @default true+ */+ hasAutoFocus?: boolean;+/** Test ID for testing frameworks. */'data-testid'?: string;}@@ -102,6 +109,7 @@ export function XDSMoreMenu({isDisabled = false,isMenuOpen,onOpenChange,+ hasAutoFocus,'data-testid': testId,ref,}: XDSMoreMenuProps) {@@ -125,6 +133,7 @@ export function XDSMoreMenu({}}items={items}hasChevron={false}+ hasAutoFocus={hasAutoFocus}data-testid={testId}/>);diff --git a/packages/core/src/Popover/Popover.doc.mjs b/packages/core/src/Popover/Popover.doc.mjsindex 467f3cc380..e48aeb6453 100644--- a/packages/core/src/Popover/Popover.doc.mjs+++ b/packages/core/src/Popover/Popover.doc.mjs@@ -77,6 +77,12 @@ export const docs = {description: 'Label for the hidden close button.',default: "'Close popover'",},+ {+ name: 'hasAutoFocus',+ type: 'boolean',+ description: 'Whether to auto-focus the first focusable element when the popover opens. Set to false for inline showcases or documentation previews.',+ default: 'true',+ },{name: 'xstyle',type: 'StyleXStyles',@@ -238,6 +244,12 @@ export const docsZh = {description: '隐藏关闭按钮的标签。',default: "'Close popover'",},+ {+ name: 'hasAutoFocus',+ type: 'boolean',+ description: '弹出框打开时是否自动聚焦第一个可聚焦元素。内联展示或文档预览设为 false。',+ default: 'true',+ },],},{@@ -354,6 +366,7 @@ export const docsDense = {label: 'Accessible label for popover dialog.',hasCloseButton: 'Whether to include hidden close button for accessibility.',closeButtonLabel: 'Label for hidden close button.',+ hasAutoFocus: 'Auto-focus first element on open; false for showcases.',},},{diff --git a/packages/core/src/Popover/XDSPopover.tsx b/packages/core/src/Popover/XDSPopover.tsxindex 96c2351c45..7271c2b046 100644--- a/packages/core/src/Popover/XDSPopover.tsx+++ b/packages/core/src/Popover/XDSPopover.tsx@@ -158,6 +158,13 @@ export interface XDSPopoverProps {*/closeButtonLabel?: string;+ /**+ * Whether to auto-focus the first focusable element when the popover opens.+ * Set to `false` for inline showcases or documentation previews.+ * @default true+ */+ hasAutoFocus?: boolean;+/*** Test ID for the popover container.*/@@ -248,6 +255,7 @@ export function XDSPopover({label,hasCloseButton,closeButtonLabel,+ hasAutoFocus,xstyle,className,style,@@ -273,6 +281,7 @@ export function XDSPopover({hasLightDismiss: true,hasCloseButton,closeButtonLabel,+ hasAutoFocus,onShow: handlePopoverShow,onHide: handlePopoverHide,});