Skip to content

Commit a2a4125

Browse files
authored
fix(Dropdown): fix menu positioning when renderOnMount=true (react-bootstrap#5989)
1 parent e3f6046 commit a2a4125

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/DropdownMenu.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
useDropdownMenu,
77
UseDropdownMenuOptions,
88
} from '@restart/ui/DropdownMenu';
9+
import useIsomorphicEffect from '@restart/hooks/useIsomorphicEffect';
910
import useMergedRefs from '@restart/hooks/useMergedRefs';
1011
import { SelectCallback } from '@restart/ui/types';
1112
import warning from 'warning';
@@ -185,6 +186,12 @@ const DropdownMenu: BsPrefixRefForwardingComponent<'div', DropdownMenuProps> =
185186
menuProps.ref,
186187
);
187188

189+
useIsomorphicEffect(() => {
190+
// Popper's initial position for the menu is incorrect when
191+
// renderOnMount=true. Need to call update() to correct it.
192+
if (show) popper?.update();
193+
}, [show]);
194+
188195
if (!hasShown && !renderOnMount && !isInputGroup) return null;
189196

190197
// For custom components provide additional, non-DOM, props;

www/src/pages/components/input-group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default withLayout(function InputGroupSection({ data }) {
6464
Button addons
6565
</LinkedHeading>
6666
<ReactPlayground codeText={Buttons} />
67-
<LinkedHeading h="2" id="input-group-buttons">
67+
<LinkedHeading h="2" id="input-group-dropdowns">
6868
Buttons with Dropdowns
6969
</LinkedHeading>
7070
<ReactPlayground codeText={ButtonDropdowns} />

0 commit comments

Comments
 (0)