-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Select): add opportunity to apply maxHeight style to popup via p…
…opupClassName property (#537)
- Loading branch information
Showing
15 changed files
with
107 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/components/Select/components/SelectPopup/SelectPopup.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@use '../../../variables'; | ||
|
||
$block: '.#{variables.$ns-new}select-popup'; | ||
|
||
#{$block} { | ||
display: flex; | ||
flex-direction: column; | ||
max-height: 90vh; | ||
} |
28 changes: 11 additions & 17 deletions
28
src/components/Select/components/SelectPopup/SelectPopup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type {Modifier} from '@popperjs/core'; | ||
import {BORDER_WIDTH, POPUP_MIN_WIDTH_IN_VIRTUALIZE_CASE} from '../../constants'; | ||
import type {SelectPopupProps} from './types'; | ||
|
||
const getMinWidth = (referenceWidth: number, virtualized?: boolean) => { | ||
if (virtualized) { | ||
return referenceWidth > POPUP_MIN_WIDTH_IN_VIRTUALIZE_CASE | ||
? referenceWidth | ||
: POPUP_MIN_WIDTH_IN_VIRTUALIZE_CASE; | ||
} | ||
|
||
return referenceWidth - BORDER_WIDTH * 2; | ||
}; | ||
|
||
export const getModifiers = ( | ||
args: Pick<SelectPopupProps, 'width' | 'disablePortal' | 'virtualized'>, | ||
) => { | ||
const {width, disablePortal, virtualized} = args; | ||
|
||
// set popper width styles according anchor rect | ||
const sameWidth: Modifier<'sameWidth', {}> = { | ||
name: 'sameWidth', | ||
enabled: true, | ||
phase: 'beforeWrite', | ||
requires: ['computeStyles'], | ||
fn: ({state}) => { | ||
// prevents styles applying after popup being opened (in case of multiple selection) | ||
if (!state.attributes.popper['data-width-set']) { | ||
const minWidth = getMinWidth(state.rects.reference.width, virtualized); | ||
state.attributes.popper['data-width-set'] = true; | ||
state.styles.popper.minWidth = `${minWidth}px`; | ||
} | ||
|
||
if (typeof width === 'number') { | ||
state.styles.popper.width = `${width}px`; | ||
} | ||
}, | ||
}; | ||
|
||
// prevents the popper from being cut off by moving it so that it stays visible within its boundary area | ||
const preventOverflow: Pick<Modifier<'preventOverflow', {}>, 'name' | 'options'> = { | ||
name: 'preventOverflow', | ||
options: {padding: 10, altBoundary: disablePortal, altAxis: true}, | ||
}; | ||
|
||
return [sameWidth, preventOverflow]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type React from 'react'; | ||
|
||
export type SelectPopupProps = { | ||
handleClose: () => void; | ||
width?: number; | ||
open?: boolean; | ||
controlRef?: React.RefObject<HTMLElement>; | ||
children?: React.ReactNode; | ||
className?: string; | ||
disablePortal?: boolean; | ||
virtualized?: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export type SelectFilterRef = { | ||
getHeight: () => number | undefined; | ||
focus: () => void; | ||
}; |
Oops, something went wrong.