Skip to content

Add support for menuScrollIntoViewElement #3531

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ export type Props = {
menuPortalTarget?: HTMLElement,
/* Whether to block scroll events when the menu is open */
menuShouldBlockScroll: boolean,
/* Custom element used when scrolling into view */
menuScrollIntoViewElement?: HTMLElement,
/* Whether the menu should be scrolled into view when it opens */
menuShouldScrollIntoView: boolean,
/* Name of the HTML Input (optional - without this, no input will be rendered) */
Expand Down Expand Up @@ -1633,6 +1635,7 @@ export default class Select extends Component<Props, State> {
menuPosition,
menuPortalTarget,
menuShouldBlockScroll,
menuScrollIntoViewElement,
menuShouldScrollIntoView,
noOptionsMessage,
onMenuScrollToTop,
Expand Down Expand Up @@ -1694,6 +1697,7 @@ export default class Select extends Component<Props, State> {
maxMenuHeight,
menuPlacement,
menuPosition,
menuScrollIntoViewElement,
menuShouldScrollIntoView,
};

Expand Down
8 changes: 7 additions & 1 deletion src/components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type PlacementArgs = {
menuEl: ElementRef<*>,
minHeight: number,
placement: 'bottom' | 'top' | 'auto',
scrollElement?: HTMLElement,
shouldScroll: boolean,
isFixedPosition: boolean,
theme: Theme,
Expand All @@ -51,12 +52,13 @@ export function getMenuPlacement({
menuEl,
minHeight,
placement,
scrollElement,
shouldScroll,
isFixedPosition,
theme,
}: PlacementArgs): MenuState {
const { spacing } = theme;
const scrollParent = getScrollParent(menuEl);
const scrollParent = scrollElement || getScrollParent(menuEl);
const defaultState = { placement: 'bottom', maxHeight };

// something went wrong, return default state
Expand Down Expand Up @@ -219,6 +221,8 @@ export type MenuAndPlacerCommon = CommonProps & {
menuPosition: MenuPosition,
/** Set the minimum height of the menu. */
minMenuHeight: number,
/* Set custom element used when scrolling into view. */
menuScrollIntoViewElement?: HTMLElement,
/** Set whether the page should scroll to show the menu. */
menuShouldScrollIntoView: boolean,
};
Expand Down Expand Up @@ -272,6 +276,7 @@ export class MenuPlacer extends Component<MenuPlacerProps, MenuState> {
maxMenuHeight,
menuPlacement,
menuPosition,
menuScrollIntoViewElement,
menuShouldScrollIntoView,
theme,
} = this.props;
Expand All @@ -284,6 +289,7 @@ export class MenuPlacer extends Component<MenuPlacerProps, MenuState> {
const shouldScroll = menuShouldScrollIntoView && !isFixedPosition;

const state = getMenuPlacement({
scrollElement: menuScrollIntoViewElement,
maxHeight: maxMenuHeight,
menuEl: ref,
minHeight: minMenuHeight,
Expand Down