Skip to content

Commit

Permalink
Merge pull request #4295 from JedWatson/fix-menuplacement-context
Browse files Browse the repository at this point in the history
  • Loading branch information
bladey authored Nov 23, 2020
2 parents 3f82ae5 + 665443b commit 709b0bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/rotten-sheep-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"react-select": patch
"@react-select/docs": patch
---

Fix menuplacement context
1 change: 1 addition & 0 deletions docs/examples/MenuPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class MenuPortal extends Component<*, State> {
menuPosition={isFixed ? 'fixed' : 'absolute'}
menuPlacement={portalPlacement}
options={colourOptions}
menuShouldScrollIntoView={false}
/>
<Note Tag="label">
<select
Expand Down
10 changes: 7 additions & 3 deletions packages/react-select/src/components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ export const menuCSS = ({
zIndex: 1,
});

const PortalPlacementContext = createContext<() => void>(() => { });
const PortalPlacementContext = createContext<{
getPortalPlacement?: (() => void) | null,
}>({ getPortalPlacement: null });

// NOTE: internal only
export class MenuPlacer extends Component<MenuPlacerProps, MenuState> {
Expand All @@ -277,7 +279,6 @@ export class MenuPlacer extends Component<MenuPlacerProps, MenuState> {
menuShouldScrollIntoView,
theme,
} = this.props;
const { getPortalPlacement } = this.context;

if (!ref) return;

Expand All @@ -295,6 +296,7 @@ export class MenuPlacer extends Component<MenuPlacerProps, MenuState> {
theme,
});

const { getPortalPlacement } = this.context;
if (getPortalPlacement) getPortalPlacement(state);

this.setState(state);
Expand Down Expand Up @@ -520,7 +522,9 @@ export class MenuPortal extends Component<MenuPortalProps, MenuPortalState> {
);

return (
<PortalPlacementContext.Provider value={this.getPortalPlacement}>
<PortalPlacementContext.Provider
value={{ getPortalPlacement: this.getPortalPlacement }}
>
{appendTo ? createPortal(menuWrapper, appendTo) : menuWrapper}
</PortalPlacementContext.Provider>
);
Expand Down

0 comments on commit 709b0bc

Please sign in to comment.