Skip to content

Commit fee13c9

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

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,19 @@ 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 = props.inheritWidthOf === 'menu' && props.maxWidth
112+
? props.maxWidth
113+
: maxWidth;
114+
115+
// .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.
116+
const style = {
117+
width: props.inheritWidthOf === 'menu' ? 'auto' : undefined,
118+
maxWidth,
119+
position: props.menuPosition !== 'relative'
120+
? 'relative'
121+
: undefined
122+
};
117123
const menuOptions = props.options.map((optionData, index) => {
118124
const active =
119125
index === props.activeOptionIndex &&

0 commit comments

Comments
 (0)