Skip to content

Commit 9db75e7

Browse files
feat: Add optional tether props to DropdownMenu (#3245)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 03b0dea commit 9db75e7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/components/dropdown-menu/DropdownMenu.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ type Props = {
2727
onMenuClose?: (event: SyntheticEvent<> | MouseEvent) => void,
2828
/** Handler for dropdown menu open events */
2929
onMenuOpen?: () => void,
30+
/** "attachment" prop for the TetherComponent, will overwrite the default settings and ignore isRightAligned option */
31+
tetherAttachment?: string,
32+
/** "targetAttachment" prop for the TetherComponent, will overwrite the default settings and ignore isRightAligned option */
33+
tetherTargetAttachment?: string,
3034
/** Set true to close dropdown menu on event bubble instead of event capture */
3135
useBubble?: boolean,
3236
};
@@ -187,6 +191,8 @@ class DropdownMenu extends React.Component<Props, State> {
187191
constrainToWindowWithPin,
188192
isResponsive,
189193
isRightAligned,
194+
tetherAttachment,
195+
tetherTargetAttachment,
190196
} = this.props;
191197

192198
const { isOpen, initialFocusIndex } = this.state;
@@ -261,13 +267,13 @@ class DropdownMenu extends React.Component<Props, State> {
261267

262268
return (
263269
<TetherComponent
264-
attachment={attachment}
270+
attachment={tetherAttachment || attachment}
265271
bodyElement={bodyEl}
266272
className={classNames({ 'bdl-DropdownMenu--responsive': isResponsive }, className)}
267273
classPrefix="dropdown-menu"
268274
constraints={constraints}
269275
enabled={isOpen}
270-
targetAttachment={targetAttachment}
276+
targetAttachment={tetherTargetAttachment || targetAttachment}
271277
>
272278
{React.cloneElement(menuButton, menuButtonProps)}
273279
{isOpen && React.cloneElement(menu, menuProps)}

src/components/dropdown-menu/__tests__/DropdownMenu.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ describe('components/dropdown-menu/DropdownMenu', () => {
203203
expect(wrapper.prop('enabled')).toBe(false);
204204
});
205205

206+
test('should render TetherComponent with attachment and targetAttachment props passed in as tetherAttachment and tetherTargetAttachment', () => {
207+
const tetherAttachment = 'middle left';
208+
const tetherTargetAttachment = 'middle right';
209+
const wrapper = shallow(
210+
<DropdownMenu
211+
isRightAligned
212+
tetherAttachment={tetherAttachment}
213+
tetherTargetAttachment={tetherTargetAttachment}
214+
>
215+
<FakeButton />
216+
<FakeMenu />
217+
</DropdownMenu>,
218+
);
219+
220+
expect(wrapper.prop('attachment')).toEqual(tetherAttachment);
221+
expect(wrapper.prop('targetAttachment')).toEqual(tetherTargetAttachment);
222+
});
223+
206224
test('should render TetherComponent with enabled prop when menu is open', () => {
207225
const wrapper = shallow(
208226
<DropdownMenu>

0 commit comments

Comments
 (0)