Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mountNode prop to combos #28661

Merged
merged 5 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Added portal slot to Combobox and Dropdown",
"packageName": "@fluentui/react-combobox",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { ComponentProps } from '@fluentui/react-utilities';
import type { ComponentState } from '@fluentui/react-utilities';
import { FC } from 'react';
import type { ForwardRefComponent } from '@fluentui/react-utilities';
import { Portal } from '@fluentui/react-portal';
import type { PositioningShorthand } from '@fluentui/react-positioning';
import { Provider } from 'react';
import { ProviderProps } from 'react';
Expand Down Expand Up @@ -50,6 +51,7 @@ export type ComboboxSlots = {
expandIcon: Slot<'span'>;
input: NonNullable<Slot<'input'>>;
listbox?: Slot<typeof Listbox>;
portal: NonNullable<Slot<typeof Portal>>;
};

// @public
Expand Down Expand Up @@ -79,6 +81,7 @@ export type DropdownSlots = {
expandIcon: Slot<'span'>;
button: NonNullable<Slot<'button'>>;
listbox?: Slot<typeof Listbox>;
portal: NonNullable<Slot<typeof Portal>>;
};

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ComboboxBaseState,
} from '../../utils/ComboboxBase.types';
import { Listbox } from '../Listbox/Listbox';
import { Portal } from '@fluentui/react-portal';

export type ComboboxSlots = {
/* The root combobox slot */
Expand All @@ -21,6 +22,11 @@ export type ComboboxSlots = {

/* The dropdown listbox slot */
listbox?: Slot<typeof Listbox>;

/* The dropdown portal slot.
Limited to setting props only as the listbox is the rendered child.
*/
portal: NonNullable<Slot<typeof Portal>>;
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @jsxRuntime classic */
/** @jsx createElement */

import { Portal } from '@fluentui/react-portal';

import { createElement } from '@fluentui/react-jsx-runtime';
Expand All @@ -24,7 +23,7 @@ export const renderCombobox_unstable = (state: ComboboxState, contextValues: Com
(state.inlinePopup ? (
<slots.listbox {...slotProps.listbox} />
) : (
<Portal>
<Portal {...slotProps.portal}>
GeoffCoxMSFT marked this conversation as resolved.
Show resolved Hide resolved
<slots.listbox {...slotProps.listbox} />
</Portal>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { Slot } from '@fluentui/react-utilities';
import type { SelectionEvents } from '../../utils/Selection.types';
import type { OptionValue } from '../../utils/OptionCollection.types';
import type { ComboboxProps, ComboboxState } from './Combobox.types';
import { Portal } from '@fluentui/react-portal';

/**
* Create the state required to render Combobox.
Expand Down Expand Up @@ -184,6 +185,10 @@ export const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLIn
})
: undefined;

const portalSlot: Slot<typeof Portal> | undefined = resolveShorthand(props.portal, {
required: true,
});

[triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);
[triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);

Expand All @@ -197,6 +202,7 @@ export const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLIn
input: 'input',
expandIcon: 'span',
listbox: Listbox,
portal: Portal,
},
root: resolveShorthand(props.root, {
required: true,
Expand All @@ -207,6 +213,7 @@ export const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLIn
}),
input: triggerSlot,
listbox: listboxSlot,
portal: portalSlot,
expandIcon: resolveShorthand(props.expandIcon, {
required: true,
defaultProps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const comboboxClassNames: SlotClassNames<ComboboxSlots> = {
input: 'fui-Combobox__input',
expandIcon: 'fui-Combobox__expandIcon',
listbox: 'fui-Combobox__listbox',
portal: 'fui-Combobox__portal',
};

// Matches internal heights for Select and Input, but there are no theme variables for these
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ComboboxBaseState,
} from '../../utils/ComboboxBase.types';
import { Listbox } from '../Listbox/Listbox';
import { Portal } from '@fluentui/react-portal';

export type DropdownSlots = {
/* The root dropdown slot */
Expand All @@ -20,6 +21,12 @@ export type DropdownSlots = {

/* The dropdown listbox slot */
listbox?: Slot<typeof Listbox>;

/*
The dropdown portal slot.
Limited to setting props only as the listbox is the rendered child.
*/
portal: NonNullable<Slot<typeof Portal>>;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const renderDropdown_unstable = (state: DropdownState, contextValues: Dro
(state.inlinePopup ? (
<slots.listbox {...slotProps.listbox} />
) : (
<Portal>
<Portal {...slotProps.portal}>
GeoffCoxMSFT marked this conversation as resolved.
Show resolved Hide resolved
<slots.listbox {...slotProps.listbox} />
</Portal>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { Slot } from '@fluentui/react-utilities';
import type { OptionValue } from '../../utils/OptionCollection.types';
import type { DropdownProps, DropdownState } from './Dropdown.types';
import { useMergedRefs } from '@fluentui/react-utilities';
import { Portal } from '@fluentui/react-portal';

/**
* Create the state required to render Dropdown.
Expand Down Expand Up @@ -130,6 +131,10 @@ export const useDropdown_unstable = (props: DropdownProps, ref: React.Ref<HTMLBu
})
: undefined;

const portalSlot: Slot<typeof Portal> | undefined = resolveShorthand(props.portal, {
required: true,
});

[triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);
[triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);

Expand All @@ -139,6 +144,7 @@ export const useDropdown_unstable = (props: DropdownProps, ref: React.Ref<HTMLBu
button: 'button',
expandIcon: 'span',
listbox: Listbox,
portal: Portal,
},
root: resolveShorthand(props.root, {
required: true,
Expand All @@ -150,6 +156,7 @@ export const useDropdown_unstable = (props: DropdownProps, ref: React.Ref<HTMLBu
}),
button: triggerSlot,
listbox: listboxSlot,
portal: portalSlot,
expandIcon: resolveShorthand(props.expandIcon, {
required: true,
defaultProps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const dropdownClassNames: SlotClassNames<DropdownSlots> = {
button: 'fui-Dropdown__button',
expandIcon: 'fui-Dropdown__expandIcon',
listbox: 'fui-Dropdown__listbox',
portal: 'fui-Dropdown__portal',
};

/**
Expand Down