An open source design system that's fully customizable and agent ready
TypeScript
fix(core): apply PowerSearch menu width (#5237)
nynexman446490d9e699beb5
diff --git a/.changeset/powersearch-applies-menuwidth-to-its-main-field--ffyn.md b/.changeset/powersearch-applies-menuwidth-to-its-main-field--ffyn.mdnew file mode 100644index 0000000000..73c5d8fba9--- /dev/null+++ b/.changeset/powersearch-applies-menuwidth-to-its-main-field--ffyn.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] PowerSearch now applies `menuWidth` to the initial field and search menu without letting it shrink below the input width. Value menus shown after selecting a field are unchanged. (#5237)+@nynexman4464diff --git a/apps/storybook/stories/PowerSearch.stories.tsx b/apps/storybook/stories/PowerSearch.stories.tsxindex 83fc1a4ae8..56b0543fee 100644--- a/apps/storybook/stories/PowerSearch.stories.tsx+++ b/apps/storybook/stories/PowerSearch.stories.tsx@@ -473,6 +473,10 @@ const meta: Meta<typeof PowerSearch> = {description:'Value results shown after selecting a field, such as people in the Owner picker.',},+ menuWidth: {+ control: 'number',+ description: 'Main field/search menu width in pixels.',+ },popoverSaveButtonLabel: {control: 'text'},size: {control: 'radio',@@ -590,6 +594,7 @@ export const IssueTracker: Story = {hasAutoFocus: true,maxSearchResults: 2,maxOperatorMenuItems: 2,+ menuWidth: 700,},parameters: {docs: {@@ -601,7 +606,7 @@ export const IssueTracker: Story = {},decorators: [Story => (- <div style={{width: 700, minHeight: 420}}>+ <div style={{width: 500, minHeight: 420}}><Story /></div>),diff --git a/packages/core/src/PowerSearch/PowerSearch.doc.mjs b/packages/core/src/PowerSearch/PowerSearch.doc.mjsindex c320833286..f5a7f5b5ee 100644--- a/packages/core/src/PowerSearch/PowerSearch.doc.mjs+++ b/packages/core/src/PowerSearch/PowerSearch.doc.mjs@@ -125,6 +125,12 @@ export const docs = {'Max ranked results for a non-empty query. Does not affect a field value editor. Browsing with an empty query shows up to 1,000 fields.',default: '10',},+ {+ name: 'menuWidth',+ type: 'number',+ description:+ 'Width in pixels for the main field/search menu. Does not affect field value editors.',+ },{name: 'popoverSaveButtonLabel',type: 'string',@@ -344,6 +350,11 @@ export const docsZh = {'非空查询的最大排名结果数。不影响字段值编辑器。使用空查询浏览时最多显示 1,000 个字段。',default: '10',},+ {+ name: 'menuWidth',+ type: 'number',+ description: '主字段/搜索菜单的像素宽度。不影响字段值编辑器。',+ },{name: 'popoverSaveButtonLabel',type: 'string',@@ -464,6 +475,7 @@ export const docsDense = {'Max suggestions in string/entity value typeaheads; excludes main field search + enum menus.',maxSearchResults:'Max ranked results for a non-empty query; excludes value editors.',+ menuWidth: 'Main field/search menu width in pixels.',popoverSaveButtonLabel: 'Label for save button in edit popover.',timezoneID: 'Timezone ID for date formatting (e.g. "America/New_York").',handleRef:diff --git a/packages/core/src/PowerSearch/PowerSearch.test.tsx b/packages/core/src/PowerSearch/PowerSearch.test.tsxindex 97545110a0..1fd3fc8dbc 100644--- a/packages/core/src/PowerSearch/PowerSearch.test.tsx+++ b/packages/core/src/PowerSearch/PowerSearch.test.tsx@@ -576,7 +576,7 @@ describe('field menu sizing', () => {};async function openMenu(- props?: {maxSearchResults?: number},+ props?: {maxSearchResults?: number; menuWidth?: number},config: PowerSearchConfig = manyFields,) {const user = userEvent.setup();@@ -639,6 +639,16 @@ describe('field menu sizing', () => {await openMenu({maxSearchResults: 3});expect(optionCount()).toBe(FIELD_COUNT);});++ it('applies menuWidth to the main field menu', async () => {+ await openMenu({menuWidth: 480});+ const listbox = screen.getByRole('listbox', {hidden: true});+ const popover = listbox.closest('[popover]');+ expect(popover).not.toBeNull();+ expect((popover as HTMLElement).style.getPropertyValue('--x-width')).toBe(+ '480px',+ );+ });});describe('field menu grouping', () => {diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsxindex ac33b58e42..c7c8e22757 100644--- a/packages/core/src/PowerSearch/PowerSearch.tsx+++ b/packages/core/src/PowerSearch/PowerSearch.tsx@@ -561,6 +561,7 @@ export function PowerSearch({onBlur,status,statusVariant = 'attached',+ menuWidth,maxTokenLength = 40,maxOperatorMenuItems,maxSearchResults = DEFAULT_MAX_SEARCH_RESULTS,@@ -1067,6 +1068,7 @@ export function PowerSearch({renderToken={renderToken}renderItem={renderItem}maxMenuItems={MAX_BROWSE_MENU_ITEMS}+ menuWidth={menuWidth}placeholder={filters.length === 0 ? placeholder : ''}hasAutoFocus={hasAutoFocus}hasClear={hasClear && !isReadOnly}diff --git a/packages/core/src/Tokenizer/Tokenizer.doc.mjs b/packages/core/src/Tokenizer/Tokenizer.doc.mjsindex 410ee5d923..abf5f3fc86 100644--- a/packages/core/src/Tokenizer/Tokenizer.doc.mjs+++ b/packages/core/src/Tokenizer/Tokenizer.doc.mjs@@ -135,6 +135,11 @@ export const docs = {description: 'Maximum number of dropdown items to display.',default: '10',},+ {+ name: 'menuWidth',+ type: 'number',+ description: 'Fixed dropdown width in pixels. The menu never shrinks below its anchor width.',+ },{name: 'emptySearchResultsText',type: 'string',@@ -384,6 +389,11 @@ export const docsZh = {description: '\u4e0b\u62c9\u5217\u8868\u663e\u793a\u7684\u6700\u5927\u9879\u76ee\u6570\u3002',default: '10',},+ {+ name: 'menuWidth',+ type: 'number',+ description: '下拉菜单的固定像素宽度。菜单不会小于其锚点宽度。',+ },{name: 'emptySearchResultsText',type: 'string',@@ -506,6 +516,7 @@ export const docsDense = {labelTooltip: 'Tooltip on label.',hasEntriesOnFocus: 'Show bootstrap results on focus before typing.',maxMenuItems: 'Max dropdown items to display.',+ menuWidth: 'Fixed dropdown width in pixels.',emptySearchResultsText: 'Text when search returns no results.',hasAutoFocus: 'Auto-focus input on mount.',size: 'Input+token size.',diff --git a/packages/core/src/Tokenizer/Tokenizer.tsx b/packages/core/src/Tokenizer/Tokenizer.tsxindex 7d20ed40fe..c6bf6d470e 100644--- a/packages/core/src/Tokenizer/Tokenizer.tsx+++ b/packages/core/src/Tokenizer/Tokenizer.tsx@@ -156,6 +156,8 @@ export interface TokenizerProps<T extends SearchableItem> extends Omit<hasEntriesOnFocus?: boolean;/** Max dropdown items. @default 10 */maxMenuItems?: number;+ /** Fixed dropdown width in pixels. Never shrinks below the input width. */+ menuWidth?: number;/** Text shown when no results found. @default 'No results found' */emptySearchResultsText?: string;/** Whether the input is disabled. @default false */@@ -393,6 +395,7 @@ export function Tokenizer<T extends SearchableItem>({placeholder,hasEntriesOnFocus,maxMenuItems,+ menuWidth,emptySearchResultsText,isDisabled = false,htmlName,@@ -778,6 +781,7 @@ export function Tokenizer<T extends SearchableItem>({placeholder={value.length === 0 ? placeholder : ''}hasEntriesOnFocus={isAtMax ? false : hasEntriesOnFocus}maxMenuItems={maxMenuItems}+ menuWidth={menuWidth}emptySearchResultsText={emptySearchResultsText}isDisabled={isDisabled}isFocusableDisabled={showsDisabledMessage}diff --git a/packages/core/src/Typeahead/BaseTypeahead.doc.mjs b/packages/core/src/Typeahead/BaseTypeahead.doc.mjsindex f3f33bde41..ba59441828 100644--- a/packages/core/src/Typeahead/BaseTypeahead.doc.mjs+++ b/packages/core/src/Typeahead/BaseTypeahead.doc.mjs@@ -60,6 +60,11 @@ export const docs = {description: 'Maximum dropdown items to display.',default: '10',},+ {+ name: 'menuWidth',+ type: 'number',+ description: 'Fixed dropdown width in pixels. The menu never shrinks below its anchor width.',+ },{name: 'emptySearchResultsText',type: 'string',@@ -169,6 +174,11 @@ export const docsZh = {description: '下拉列表显示的最大项目数。',default: '10',},+ {+ name: 'menuWidth',+ type: 'number',+ description: '下拉菜单的固定像素宽度。菜单不会小于其锚点宽度。',+ },{name: 'emptySearchResultsText',type: 'string',@@ -253,6 +263,7 @@ export const docsDense = {placeholder: 'Input placeholder.',hasEntriesOnFocus: 'Bootstrap results on focus.',maxMenuItems: 'Max dropdown items.',+ menuWidth: 'Fixed dropdown width in pixels.',emptySearchResultsText: 'Text when no results.',isDisabled: 'Whether input disabled.',hasAutoFocus: 'Auto-focus on mount.',diff --git a/packages/core/src/Typeahead/BaseTypeahead.tsx b/packages/core/src/Typeahead/BaseTypeahead.tsxindex 65c27b939d..287b128646 100644--- a/packages/core/src/Typeahead/BaseTypeahead.tsx+++ b/packages/core/src/Typeahead/BaseTypeahead.tsx@@ -94,6 +94,9 @@ export interface BaseTypeaheadProps<T extends SearchableItem> extends Omit<*/maxMenuItems?: number;+ /** Fixed dropdown width in pixels. Never shrinks below the anchor width. */+ menuWidth?: number;+/*** Text shown when no results found.* @default 'No results found'@@ -227,6 +230,9 @@ const styles = stylex.create({popover: {minWidth: 'anchor-size(width)',},+ popoverCustomWidth: (width: number) => ({+ width: `${width}px`,+ }),groupHeading: {paddingInline: spacingVars['--spacing-2'],paddingBlockStart: spacingVars['--spacing-2'],@@ -326,6 +332,7 @@ export const BaseTypeahead = function BaseTypeahead<T extends SearchableItem>({placeholder: placeholderFromProps,hasEntriesOnFocus = false,maxMenuItems = 10,+ menuWidth,emptySearchResultsText: emptySearchResultsTextFromProps,isDisabled = false,isFocusableDisabled = false,@@ -914,7 +921,10 @@ export const BaseTypeahead = function BaseTypeahead<T extends SearchableItem>({placement: 'below',alignment: 'start',offset: spacingVars['--spacing-1'],- xstyle: styles.popover,+ xstyle: [+ styles.popover,+ menuWidth != null && styles.popoverCustomWidth(menuWidth),+ ],},)}</>