Skip to content

Commit

Permalink
fix(select): pass portalContainer to the pop-over
Browse files Browse the repository at this point in the history
  • Loading branch information
macci001 committed Sep 1, 2024
1 parent f36df43 commit 29de544
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/clean-eagles-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/select": patch
---

Currently the select component do not pass the portalContainer prop to it's child pop-over. The pop-over hence takes default value of portalContainer i.e document.body. Due to this, when parent of the select component is scrollable, the scroll closes the pop-over immediately due to the scroll. This makes it impossible for the pop-over to open.The PR adds the portalContainer prop to the pop-over.
7 changes: 6 additions & 1 deletion packages/components/select/src/use-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export function useSelect<T extends object>(originalProps: UseSelectProps<T>) {
const triggerRef = useRef<HTMLElement>(null);
const listBoxRef = useRef<HTMLUListElement>(null);
const popoverRef = useRef<HTMLDivElement>(null);
const baseRef = useRef<HTMLDivElement>(null);

let state = useMultiSelectState<T>({
...props,
Expand Down Expand Up @@ -380,6 +381,7 @@ export function useSelect<T extends object>(originalProps: UseSelectProps<T>) {

const getBaseProps: PropGetter = useCallback(
(props = {}) => ({
ref: baseRef,
"data-slot": "base",
"data-filled": dataAttr(isFilled),
"data-has-value": dataAttr(hasValue),
Expand All @@ -391,7 +393,7 @@ export function useSelect<T extends object>(originalProps: UseSelectProps<T>) {
}),
...props,
}),
[slots, hasHelper, hasValue, hasLabel, isFilled, baseStyles],
[baseRef, slots, hasHelper, hasValue, hasLabel, isFilled, baseStyles],
);

const getTriggerProps: PropGetter = useCallback(
Expand Down Expand Up @@ -519,6 +521,7 @@ export function useSelect<T extends object>(originalProps: UseSelectProps<T>) {
"data-slot": "popover",
scrollRef: listBoxRef,
triggerType: "listbox",
portalContainer: baseRef.current ?? undefined,
classNames: {
content: slots.popoverContent({
class: clsx(classNames?.popoverContent, props.className),
Expand All @@ -540,6 +543,8 @@ export function useSelect<T extends object>(originalProps: UseSelectProps<T>) {
classNames?.popoverContent,
slotsProps.popoverProps,
triggerRef,
listBoxRef,
baseRef,
state,
state.selectedItems,
],
Expand Down

0 comments on commit 29de544

Please sign in to comment.