From c4765b48953ac9be7f964d9ccf573c545dd5de5a Mon Sep 17 00:00:00 2001 From: Sarah Higley Date: Thu, 8 Sep 2022 16:19:37 -0700 Subject: [PATCH 1/3] set listbox popup width to trigger width --- .../react-combobox/src/utils/useTriggerListboxSlots.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/react-components/react-combobox/src/utils/useTriggerListboxSlots.ts b/packages/react-components/react-combobox/src/utils/useTriggerListboxSlots.ts index c90f3f1e02fa2..bb535f187e950 100644 --- a/packages/react-components/react-combobox/src/utils/useTriggerListboxSlots.ts +++ b/packages/react-components/react-combobox/src/utils/useTriggerListboxSlots.ts @@ -52,9 +52,17 @@ export function useTriggerListboxSlots( // handle trigger focus/blur const triggerRef: typeof ref = React.useRef(null); + // calculate listbox width style based on trigger width + const [popupWidth, setPopupWidth] = React.useState(); + React.useEffect(() => { + const width = open ? triggerRef.current?.clientWidth : undefined; + setPopupWidth(width); + }, [open]); + // resolve listbox shorthand props const listbox: typeof listboxSlot = listboxSlot && { multiselect, + style: { width: `${popupWidth}px` }, tabIndex: undefined, ...listboxSlot, }; From c562fe26de37a363ccdef81d2b4e3d3d05ba93fe Mon Sep 17 00:00:00 2001 From: Sarah Higley Date: Thu, 8 Sep 2022 16:20:48 -0700 Subject: [PATCH 2/3] change file --- ...eact-combobox-7bb9e1fd-dd15-4dd6-bdff-951b259e85db.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@fluentui-react-combobox-7bb9e1fd-dd15-4dd6-bdff-951b259e85db.json diff --git a/change/@fluentui-react-combobox-7bb9e1fd-dd15-4dd6-bdff-951b259e85db.json b/change/@fluentui-react-combobox-7bb9e1fd-dd15-4dd6-bdff-951b259e85db.json new file mode 100644 index 0000000000000..b33f444d83e51 --- /dev/null +++ b/change/@fluentui-react-combobox-7bb9e1fd-dd15-4dd6-bdff-951b259e85db.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "fix: set popup Listbox width to trigger width", + "packageName": "@fluentui/react-combobox", + "email": "sarah.higley@microsoft.com", + "dependentChangeType": "patch" +} From eaf65bc17c6e1aa7c3089bb7caf53f5c3312172b Mon Sep 17 00:00:00 2001 From: Sarah Higley Date: Fri, 9 Sep 2022 14:04:03 -0700 Subject: [PATCH 3/3] base listbox width off root width --- .../__snapshots__/Combobox.test.tsx.snap | 2 +- .../src/components/Combobox/useCombobox.tsx | 16 +++++++++++++++- .../__snapshots__/Dropdown.test.tsx.snap | 2 +- .../src/components/Dropdown/useDropdown.tsx | 16 +++++++++++++++- .../src/utils/useTriggerListboxSlots.ts | 8 -------- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/packages/react-components/react-combobox/src/components/Combobox/__snapshots__/Combobox.test.tsx.snap b/packages/react-components/react-combobox/src/components/Combobox/__snapshots__/Combobox.test.tsx.snap index be8774d5ac05a..387507376d143 100644 --- a/packages/react-components/react-combobox/src/components/Combobox/__snapshots__/Combobox.test.tsx.snap +++ b/packages/react-components/react-combobox/src/components/Combobox/__snapshots__/Combobox.test.tsx.snap @@ -68,7 +68,7 @@ exports[`Combobox renders an open listbox 1`] = `
(null); const triggerRef = React.useRef(null); + // calculate listbox width style based on trigger width + const [popupWidth, setPopupWidth] = React.useState(); + React.useEffect(() => { + const width = open ? `${rootRef.current?.clientWidth}px` : undefined; + setPopupWidth(width); + }, [open]); + + // handle input type-to-select const getSearchString = (inputValue: string): string => { // if there are commas in the value string, take the text after the last comma const searchString = inputValue.split(',').pop(); @@ -150,7 +159,10 @@ export const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref
(null); + const [popupWidth, setPopupWidth] = React.useState(); + React.useEffect(() => { + const width = open ? `${rootRef.current?.clientWidth}px` : undefined; + setPopupWidth(width); + }, [open]); + // jump to matching option based on typing const searchString = React.useRef(''); const [setKeyTimeout, clearKeyTimeout] = useTimeout(); @@ -108,7 +117,10 @@ export const useDropdown_unstable = (props: DropdownProps, ref: React.Ref(); - React.useEffect(() => { - const width = open ? triggerRef.current?.clientWidth : undefined; - setPopupWidth(width); - }, [open]); - // resolve listbox shorthand props const listbox: typeof listboxSlot = listboxSlot && { multiselect, - style: { width: `${popupWidth}px` }, tabIndex: undefined, ...listboxSlot, };