-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: combobox inside of popover bug (#4049)
- Loading branch information
Showing
13 changed files
with
254 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@twilio-paste/combobox": minor | ||
"@twilio-paste/core": minor | ||
--- | ||
|
||
[Combobox] Add new prop `usePortal` which defaults to `true`. The prop was introduced to address a bug when Comboboxes are placed in Popovers. usePortal should be set to false when using a Combobox inside a Popover in order to retain full functionality. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/paste-core/components/combobox/src/ListboxWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Box } from "@twilio-paste/box"; | ||
import { Portal } from "@twilio-paste/reakit-library"; | ||
import * as React from "react"; | ||
|
||
import { ListBoxPositioner } from "./ListboxPositioner"; | ||
|
||
/* | ||
* This component renders the listbox in an absolutely positioned Box when `usePortal={false}`. | ||
* Portal and ListBoxPositioner shouldn't be used when the Combobox is placed in a Popover. | ||
* Using Combobox in a Popover was previously causing interaction issues because of the Portal that Popover uses. | ||
* Because ListBoxPositioner isn't used when `usePortal={false}`, the listbox won't change position based on the window | ||
* (e.g. moving above the input box when the Combobox is at the bottom of the window). | ||
*/ | ||
|
||
export const ListboxWrapper: React.FC<{ | ||
inputBoxRef: React.RefObject<HTMLElement>; | ||
parentRef: React.RefObject<HTMLElement>; | ||
usePortal: boolean; | ||
children: React.ReactNode; | ||
}> = ({ inputBoxRef, parentRef, usePortal, children }) => { | ||
if (!usePortal) | ||
return ( | ||
<Box position="absolute" top="100%" width="100%"> | ||
{children} | ||
</Box> | ||
); | ||
return ( | ||
<Portal> | ||
<ListBoxPositioner inputBoxRef={inputBoxRef} dropdownBoxRef={parentRef}> | ||
{children} | ||
</ListBoxPositioner> | ||
</Portal> | ||
); | ||
}; | ||
ListboxWrapper.displayName = "ListboxWrapper"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.