Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
},
"dependencies": {
"@floating-ui/react": "^0.26.0",
"@patternfly/react-icons": "workspace:^",
"@patternfly/react-styles": "workspace:^",
"@patternfly/react-tokens": "workspace:^",
Expand Down
8 changes: 7 additions & 1 deletion packages/react-core/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { forwardRef, useEffect, useRef } from 'react';
import { css } from '@patternfly/react-styles';
import { Menu, MenuContent, MenuProps } from '../Menu';
import { Popper } from '../../helpers/Popper/Popper';
import { FloatingUIPopper } from '../../helpers/FloatingUI/FloatingUIPopper';
import { getOUIAProps, OUIAProps, getDefaultOUIAId, onToggleArrowKeydownDefault } from '../../helpers';

export interface SelectPopperProps {
Expand Down Expand Up @@ -86,6 +87,8 @@ export interface SelectProps extends MenuProps, OUIAProps {
shouldPreventScrollOnItemFocus?: boolean;
/** Time in ms to wait before firing the toggles' focus event. Defaults to 0 */
focusTimeoutDelay?: number;
/** @beta Flag to use Floating UI instead of Popper for positioning. Defaults to false. If you're seeing positioning issues with the default Select component, try setting this flag to true. */
useFloatingUI?: boolean;
}

const SelectBase: React.FunctionComponent<SelectProps & OUIAProps> = ({
Expand All @@ -111,6 +114,7 @@ const SelectBase: React.FunctionComponent<SelectProps & OUIAProps> = ({
isScrollable,
shouldPreventScrollOnItemFocus = true,
focusTimeoutDelay = 0,
useFloatingUI = false,
...props
}: SelectProps & OUIAProps) => {
const localMenuRef = useRef<HTMLDivElement>(undefined);
Expand Down Expand Up @@ -212,8 +216,10 @@ const SelectBase: React.FunctionComponent<SelectProps & OUIAProps> = ({
</MenuContent>
</Menu>
);
const PopperComponent = useFloatingUI ? FloatingUIPopper : Popper;

return (
<Popper
<PopperComponent
trigger={typeof toggle === 'function' ? toggle(toggleRef) : toggle.toggleNode}
triggerRef={toggleRef}
popper={menu}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const SelectBasic: React.FunctionComponent = () => {
onOpenChange={(isOpen) => setIsOpen(isOpen)}
toggle={toggle}
shouldFocusToggleOnSelect
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList>
<SelectOption value="Option 1">Option 1</SelectOption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const SelectCheckbox: React.FunctionComponent = () => {
onSelect={onSelect}
onOpenChange={(nextOpen: boolean) => setIsOpen(nextOpen)}
toggle={toggle}
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList>
<SelectOption hasCheckbox value={0} isSelected={selectedItems.includes(0)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const SelectFooter: React.FunctionComponent = () => {
id="menu-with-footer"
onSelect={onSelect}
selected={selected}
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList>
<SelectOption value="Option 1">Option 1</SelectOption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const SelectGrouped: React.FunctionComponent = () => {
onOpenChange={(isOpen) => setIsOpen(isOpen)}
toggle={toggle}
shouldFocusToggleOnSelect
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectGroup label="Group 1">
<SelectList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export const SelectMultiTypeahead: React.FunctionComponent = () => {
}}
toggle={toggle}
variant="typeahead"
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList isAriaMultiselectable id="select-multi-typeahead-listbox">
{selectOptions.map((option, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export const SelectMultiTypeaheadCheckbox: React.FunctionComponent = () => {
}}
toggle={toggle}
variant="typeahead"
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList isAriaMultiselectable id="select-multi-typeahead-checkbox-listbox">
{selectOptions.map((option, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export const SelectMultiTypeaheadCreatable: React.FunctionComponent = () => {
}}
toggle={toggle}
variant="typeahead"
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList isAriaMultiselectable id="select-multi-create-typeahead-listbox">
{selectOptions.map((option, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const SelectOptionVariations: React.FunctionComponent = () => {
onOpenChange={(isOpen) => setIsOpen(isOpen)}
toggle={toggle}
shouldFocusToggleOnSelect
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList>
<SelectOption value="Basic option">Basic option</SelectOption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const SelectTypeahead: React.FunctionComponent = () => {
}}
toggle={toggle}
variant="typeahead"
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList id="select-typeahead-listbox">
{selectOptions.map((option, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export const SelectTypeaheadCreatable: React.FunctionComponent = () => {
}}
toggle={toggle}
variant="typeahead"
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList id="select-create-typeahead-listbox">
{selectOptions.map((option, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const SelectValidated: React.FunctionComponent = () => {
onOpenChange={(isOpen) => setIsOpen(isOpen)}
toggle={toggle}
shouldFocusToggleOnSelect
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList>
<SelectOption value="Success">Success</SelectOption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const SelectViewMore: React.FunctionComponent = () => {
onSelect={onSelect}
onOpenChange={(isOpen) => setIsOpen(isOpen)}
toggle={{ toggleNode: toggle, toggleRef }}
useFloatingUI // FloatingUI is recommended for better positioning. Will become the default in future breaking change.
>
<SelectList>
{visibleOptions.map((option) => {
Expand Down
Loading
Loading