Grafana UI: Add scroll handlers to the Select component (#65069)

* [feat] Add scroll handlers to the Select component

* [refactor] Update Select component

- Update how `captureMenuScroll` boolean is set
- Update props

* [fix] revert unexpected changes
This commit is contained in:
Ben Simpson
2023-06-12 13:52:23 +01:00
committed by GitHub
parent 176a98dda8
commit d363741d39
2 changed files with 10 additions and 1 deletions

View File

@@ -131,6 +131,8 @@ export function SelectBase<T>({
onCreateOption,
onInputChange,
onKeyDown,
onMenuScrollToBottom,
onMenuScrollToTop,
onOpenMenu,
onFocus,
openMenuOnFocus = false,
@@ -215,7 +217,7 @@ export function SelectBase<T>({
autoFocus,
backspaceRemovesValue,
blurInputOnSelect,
captureMenuScroll: false,
captureMenuScroll: onMenuScrollToBottom || onMenuScrollToTop,
closeMenuOnSelect,
// We don't want to close if we're actually scrolling the menu
// So only close if none of the parents are the select menu itself
@@ -252,6 +254,8 @@ export function SelectBase<T>({
onKeyDown,
onMenuClose: onCloseMenu,
onMenuOpen: onOpenMenu,
onMenuScrollToBottom: onMenuScrollToBottom,
onMenuScrollToTop: onMenuScrollToTop,
onFocus,
formatOptionLabel,
openMenuOnFocus,

View File

@@ -24,6 +24,7 @@ export interface SelectCommonProps<T> {
autoFocus?: boolean;
backspaceRemovesValue?: boolean;
blurInputOnSelect?: boolean;
captureMenuScroll?: boolean;
className?: string;
closeMenuOnSelect?: boolean;
/** Used for custom components. For more information, see `react-select` */
@@ -70,6 +71,10 @@ export interface SelectCommonProps<T> {
onCreateOption?: (value: string) => void;
onInputChange?: (value: string, actionMeta: InputActionMeta) => void;
onKeyDown?: (event: React.KeyboardEvent) => void;
/** Callback which fires when the user scrolls to the bottom of the menu */
onMenuScrollToBottom?: (event: WheelEvent | TouchEvent) => void;
/** Callback which fires when the user scrolls to the top of the menu */
onMenuScrollToTop?: (event: WheelEvent | TouchEvent) => void;
onOpenMenu?: () => void;
onFocus?: () => void;
openMenuOnFocus?: boolean;