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 authored and Maharshi Alpesh committed Sep 6, 2024
1 parent 60cd878 commit c4ec259
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 @@ -231,6 +231,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 @@ -379,6 +380,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 @@ -390,7 +392,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 @@ -518,6 +520,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 @@ -536,6 +539,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 c4ec259

Please sign in to comment.