Skip to content

Commit de78475

Browse files
Combobox: Allow PopperJS to position menu correctly
This enables dialog flip and preventing overflow
1 parent 65afb01 commit de78475

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

components/combobox/combobox.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ class Combobox extends React.Component {
10401040
}
10411041
labels={labels}
10421042
menuItem={this.props.menuItem}
1043+
menuPosition={this.props.menuPosition}
10431044
maxWidth={this.props.menuMaxWidth}
10441045
options={this.props.options}
10451046
onSelect={this.handleSelect}

components/combobox/private/menu.jsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,18 @@ const propTypes = {
107107
const defaultProps = {};
108108

109109
const Menu = (props) => {
110-
const style =
111-
props.inheritWidthOf === 'menu'
112-
? {
113-
width: 'auto',
114-
maxWidth: props.maxWidth ? props.maxWidth : 'inherit',
115-
}
116-
: undefined;
110+
let maxWidth = props.inheritWidthOf === 'menu' ? 'inherit' : undefined;
111+
maxWidth =
112+
props.inheritWidthOf === 'menu' && props.maxWidth
113+
? props.maxWidth
114+
: maxWidth;
115+
116+
// .slds-dropdown sets the menu to absolute positioning, since it has a relative parent. Absolute positioning removes clientHeight and clientWidth which Popper.js needs to absolute position the menu's wrapping div. Absolute positioning an already absolute positioned element doesn't work. Setting the menu's position to relative allows PopperJS to work it's magic.
117+
const style = {
118+
width: props.inheritWidthOf === 'menu' ? 'auto' : undefined,
119+
maxWidth,
120+
position: props.menuPosition !== 'relative' ? 'relative' : undefined,
121+
};
117122
const menuOptions = props.options.map((optionData, index) => {
118123
const active =
119124
index === props.activeOptionIndex &&

0 commit comments

Comments
 (0)