Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute EuiComboBox's listbox zIndex #3551

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

**Bug fixes**
- Fixed `EuiKeyPadMenu` and `EuiKeyPadMenuItem` aria roles ([#3502](https://github.com/elastic/eui/pull/3502))
- Fixed `EuiComboBox`'s options list `zIndex` positioning when nested in other `zIndex` contexts ([#3551](https://github.com/elastic/eui/pull/3551))
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved

## [`24.1.0`](https://github.com/elastic/eui/tree/v24.1.0)

Expand Down
24 changes: 24 additions & 0 deletions src-docs/src/views/flyout/flyout_complicated.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
EuiButton,
EuiButtonEmpty,
EuiCodeBlock,
EuiComboBox,
EuiExpression,
EuiFlexGroup,
EuiFlexItem,
EuiFlyout,
Expand All @@ -26,6 +28,7 @@ export default () => {
const [isFlyoutVisible, setIsFlyoutVisible] = useState(false);
const [selectedTabId, setSelectedTabId] = useState('1');
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [isExpressionOpen, setIsExpressionOpen] = useState(false);

const tabs = [
{
Expand Down Expand Up @@ -163,6 +166,27 @@ export default () => {
</EuiFormRow>
</EuiForm>
<EuiSpacer />
<EuiPopover
isOpen={isExpressionOpen}
closePopover={() => setIsExpressionOpen(false)}
ownFocus={true}
button={
<EuiExpression
description="expression"
value="configurations"
onClick={() => setIsExpressionOpen(!isExpressionOpen)}
/>
}>
<EuiComboBox
selectedOptions={[{ label: 'Option one' }]}
options={[
{ label: 'Option one' },
{ label: 'Option two' },
{ label: 'Option three' },
]}
/>
</EuiPopover>
<EuiSpacer />
{flyoutContent}
<EuiCodeBlock language="html">{htmlCode}</EuiCodeBlock>
</EuiFlyoutBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ exports[`props options list is rendered 1`] = `
<div
class="euiPanel euiComboBoxOptionsList euiComboBoxOptionsList--bottom"
data-test-subj="comboBoxOptionsList alsoGetsAppliedToOptionsList-optionsList"
style="z-index: 0;"
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
>
<div
class="euiComboBoxOptionsList__rowWrap"
Expand Down
14 changes: 14 additions & 0 deletions src/components/combo_box/combo_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { EuiFilterSelectItem } from '../filter_group';
import AutosizeInput from 'react-input-autosize';
import { CommonProps } from '../common';
import { EuiFormControlLayoutProps } from '../form';
import { getElementZIndex } from '../../services/popover';

type DrillProps<T> = Pick<
EuiComboBoxOptionsListProps<T>,
Expand Down Expand Up @@ -178,6 +179,7 @@ interface EuiComboBoxState<T> {
isListOpen: boolean;
listElement?: RefInstance<HTMLDivElement>;
listPosition: EuiComboBoxOptionsListPosition;
listZIndex: number | undefined;
matchingOptions: Array<EuiComboBoxOptionOption<T>>;
searchValue: string;
width: number;
Expand Down Expand Up @@ -208,6 +210,7 @@ export class EuiComboBox<T> extends Component<
isListOpen: false,
listElement: null,
listPosition: 'bottom',
listZIndex: undefined,
matchingOptions: getMatchingOptions<T>(
this.props.options,
this.props.selectedOptions,
Expand Down Expand Up @@ -262,6 +265,15 @@ export class EuiComboBox<T> extends Component<

listRefInstance: RefInstance<HTMLDivElement> = null;
listRefCallback: RefCallback<HTMLDivElement> = ref => {
if (this.comboBoxRefInstance) {
// find the zIndex of the combobox relative to the page body
// and use that to depth-position the list box
const listZIndex = getElementZIndex(
this.comboBoxRefInstance,
document.body
);
this.setState({ listZIndex });
}
this.listRefInstance = ref;
};

Expand Down Expand Up @@ -291,6 +303,7 @@ export class EuiComboBox<T> extends Component<
closeList = () => {
this.clearActiveOption();
this.setState({
listZIndex: undefined,
isListOpen: false,
});
};
Expand Down Expand Up @@ -969,6 +982,7 @@ export class EuiComboBox<T> extends Component<
optionsList = (
<EuiPortal>
<EuiComboBoxOptionsList
zIndex={this.state.listZIndex}
activeOptionIndex={this.state.activeOptionIndex}
areAllOptionsSelected={this.areAllOptionsSelected()}
data-test-subj={optionsListDataTestSubj}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type EuiComboBoxOptionsListProps<T> = CommonProps &
width: number;
singleSelection?: boolean | EuiComboBoxSingleSelectionShape;
delimiter?: string;
zIndex?: number;
};

export class EuiComboBoxOptionsList<T> extends Component<
Expand Down Expand Up @@ -200,6 +201,8 @@ export class EuiComboBoxOptionsList<T> extends Component<
updatePosition,
width,
delimiter,
zIndex,
style,
...rest
} = this.props;

Expand Down Expand Up @@ -383,6 +386,7 @@ export class EuiComboBoxOptionsList<T> extends Component<
className={classes}
panelRef={this.listRefCallback}
data-test-subj={`comboBoxOptionsList ${dataTestSubj}`}
style={{ ...style, zIndex: zIndex }}
{...rest}>
<div className="euiComboBoxOptionsList__rowWrap">
{emptyState || optionsList}
Expand Down