Skip to content

Conversation

nicolethoen
Copy link
Contributor

introduce variant of Select using FloatingUI to use optionally instead of Popper

Closes #12000
Closes #12001

@patternfly-build
Copy link
Contributor

patternfly-build commented Sep 11, 2025

@nicolethoen nicolethoen changed the title feat(Select): introduce variant of Select using FloatingUI feat(Select): introduce variant of Select using FloatingUI [WIP] Sep 11, 2025
Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial file comments below. Overall this looks great, and the best part when changing useFloatingUI to true by default:

Local stage theme menu properly repositioned instead of causing a horizontal overflow

One question regarding the future of using FloatingUI: do we plan to rebuild the API to be a little more inline with Floating UI rather than trying to keep the API consistent for now? Seems like there may be additional/alternative properties we could try leveraging from FloatingUI, and just pondering whether our API would work longterm or if it would make for a better consumer experience to clean things up further in a breaking change.


return (
<>
{trigger && !triggerRef && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line might be what's causing things to not render? Updating to trigger && !!triggerRef renders things again. Issue stems from Select always having triggerRef defined.

// Configure middleware
const middleware = useMemo(() => {
const middlewareArray = [
offset(distance),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd probably want to allow passing a single number or the offset object to allow more custom override, just to try and mimic what was done in https://github.com/patternfly/patternfly-react/pull/11994/files

Comment on lines +476 to +480
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onFocus={handleFocus}
onBlur={handleBlur}
onClick={handleTriggerClick}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should defined these and place them on the div here. At least for the onClick, this could result in unexpected firings since the div could be wider than the trigger itself.

Comment on lines +324 to +329
const { refs, floatingStyles, context } = useFloating({
placement: floatingUIPlacement,
middleware,
open: showPopper,
whileElementsMounted: autoUpdate
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we have to pass the onOpenChange option here and tweak how we're handling that in other components? Pressing Escape doesn't close the Select menu when it's opened when using the floating UI.

Comment on lines +27 to +34
const getLanguageDirection = (targetElement: HTMLElement = document.body, defaultDirection: 'ltr' | 'rtl' = 'ltr') => {
if (!targetElement) {
return defaultDirection;
}
const computedStyle = window.getComputedStyle(targetElement);
const direction = computedStyle.direction;
return direction === 'rtl' ? 'rtl' : 'ltr';
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could import the getLanguageDirection helper from utils instead of redefining it here

const languageDirection = getLanguageDirection(document.body);

// Handle position mapping with RTL support
const internalPosition = useMemo<'left' | 'right' | 'center'>(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might not be passing correct stuff in when testing, or I'm expecting the wrong thing. When I open a Select example ("Select option variants" since it's popper menu is wider than the toggle), by default the popper content extends to the right beyond the toggle. When I toggle RTL to be on, I was expecting the popper menu to then extend to the left beyond the toggle, but it still extends to the right

Default LTR view:
Select menu opened in LTR mode, showing the menu extending to the directional right of the toggle

RTL view:
Select menu opened in RTL mode, showing the menu still extending to the directional right of the toggle

This may not be something we have to address immediately since we currently have issues with this anyway, but just wanted to mention it in case we're expectng this behavior to work differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants