Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make MenuPlacer component customizable and switchable.
- Loading branch information
Showing
9 changed files
with
88 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"react-select": patch | ||
"@react-select/docs": patch | ||
--- | ||
|
||
Make "MenuPlacer" component customizable and switchable. |
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,44 @@ | ||
import React, { RefCallback } from 'react'; | ||
import Select, { MenuPlacerProps, PlacerProps } from 'react-select'; | ||
import { | ||
ColourOption, | ||
colourOptions, | ||
FlavourOption, | ||
GroupedOption, | ||
groupedOptions, | ||
} from '../data'; | ||
|
||
const MenuPlacer = ( | ||
props: MenuPlacerProps<ColourOption | FlavourOption, false, GroupedOption> | ||
) => { | ||
const { children } = props; | ||
|
||
const getCustomPlacement: RefCallback<HTMLDivElement> = (ref) => { | ||
if (!ref) return; | ||
// custom implementation of getPlacement | ||
}; | ||
|
||
const getUpdatedProps: () => PlacerProps = () => { | ||
return { | ||
placement: 'top', | ||
maxHeight: 200, | ||
}; | ||
}; | ||
|
||
return ( | ||
<> | ||
{children({ | ||
ref: getCustomPlacement, | ||
placerProps: getUpdatedProps(), | ||
})} | ||
</> | ||
); | ||
}; | ||
|
||
export default () => ( | ||
<Select<ColourOption | FlavourOption, false, GroupedOption> | ||
defaultValue={colourOptions[1]} | ||
options={groupedOptions} | ||
components={{ MenuPlacer }} | ||
/> | ||
); |
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
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