Select: Expose menuPortalTarget on SelectBase (#37456)

* Select: Expose Select props for greater flexibility

* Select: only expose menuPortalTarget

* Select: Add deprecation notice for menuPortalTarget prop

* Select: Add deprecation warning to component
This commit is contained in:
Ashley Harrison
2021-08-03 11:55:09 +02:00
committed by GitHub
parent e530d66275
commit 9934c883cc
2 changed files with 14 additions and 1 deletions
@@ -20,6 +20,7 @@ import { useTheme2 } from '../../themes';
import { getSelectStyles } from './getSelectStyles'; import { getSelectStyles } from './getSelectStyles';
import { cleanValue, findSelectedValue } from './utils'; import { cleanValue, findSelectedValue } from './utils';
import { SelectBaseProps, SelectValue } from './types'; import { SelectBaseProps, SelectValue } from './types';
import { deprecationWarning } from '@grafana/data';
interface ExtraValuesIndicatorProps { interface ExtraValuesIndicatorProps {
maxVisibleValues?: number | undefined; maxVisibleValues?: number | undefined;
@@ -116,6 +117,7 @@ export function SelectBase<T>({
minMenuHeight, minMenuHeight,
maxVisibleValues, maxVisibleValues,
menuPlacement = 'auto', menuPlacement = 'auto',
menuPortalTarget,
menuPosition, menuPosition,
noOptionsMessage = 'No options found', noOptionsMessage = 'No options found',
onBlur, onBlur,
@@ -136,6 +138,11 @@ export function SelectBase<T>({
width, width,
isValidNewOption, isValidNewOption,
}: SelectBaseProps<T>) { }: SelectBaseProps<T>) {
if (menuPortalTarget !== undefined) {
deprecationWarning('SelectBase', 'menuPortalTarget');
} else {
menuPortalTarget = document.body;
}
const theme = useTheme2(); const theme = useTheme2();
const styles = getSelectStyles(theme); const styles = getSelectStyles(theme);
const onChangeWithEmpty = useCallback( const onChangeWithEmpty = useCallback(
@@ -199,7 +206,7 @@ export function SelectBase<T>({
maxVisibleValues, maxVisibleValues,
menuIsOpen: isOpen, menuIsOpen: isOpen,
menuPlacement, menuPlacement,
menuPortalTarget: document.body, menuPortalTarget,
menuPosition, menuPosition,
menuShouldBlockScroll: true, menuShouldBlockScroll: true,
menuShouldScrollIntoView: false, menuShouldScrollIntoView: false,
@@ -41,6 +41,12 @@ export interface SelectCommonProps<T> {
minMenuHeight?: number; minMenuHeight?: number;
maxVisibleValues?: number; maxVisibleValues?: number;
menuPlacement?: 'auto' | 'bottom' | 'top'; menuPlacement?: 'auto' | 'bottom' | 'top';
/**
* @deprecated Setting `menuPortalTarget` to null will revert to previous `Select` behaviour.
* This is provided as an escape hatch for cases where portalling is a breaking change (e.g. `Select` wrapped in `ClickOutsideWrapper`).
* It's recommended to achieve the same behaviour using `onCloseMenu`, as this will be removed at some point.
*/
menuPortalTarget?: HTMLElement | null;
menuPosition?: 'fixed' | 'absolute'; menuPosition?: 'fixed' | 'absolute';
/** The message to display when no options could be found */ /** The message to display when no options could be found */
noOptionsMessage?: string; noOptionsMessage?: string;