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 4 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## [`master`](https://github.com/elastic/eui/tree/master)

**Breaking changes**
- Removed `$euiZComboBox` SCSS variable (value was 8001) ([#3551](https://github.com/elastic/eui/pull/3551))

**Bug fixes**

- Fixed `EuiCodeBlockImpl` testenv mock pass-through of `data-test-subj` attribute ([#3560](https://github.com/elastic/eui/pull/3560))
- 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

## [`25.0.0`](https://github.com/elastic/eui/tree/v25.0.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 [selectedTabId, setSelectedTabId] = useState('1');
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [superSelectvalue, setSuperSeelctValue] = useState('option_one');
const [isExpressionOpen, setIsExpressionOpen] = useState(false);

const tabs = [
{
Expand Down Expand Up @@ -218,6 +221,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: 100;"
>
<div
class="euiComboBoxOptionsList__rowWrap"
Expand Down
13 changes: 13 additions & 0 deletions src/components/combo_box/combo_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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 @@ -173,6 +174,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 @@ -203,6 +205,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 @@ -257,6 +260,14 @@ 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
// adds an extra `100` to provide some defense around neighboring elements' positioning
const listZIndex =
getElementZIndex(this.comboBoxRefInstance, document.body) + 100;
this.setState({ listZIndex });
}
this.listRefInstance = ref;
};

Expand Down Expand Up @@ -286,6 +297,7 @@ export class EuiComboBox<T> extends Component<
closeList = () => {
this.clearActiveOption();
this.setState({
listZIndex: undefined,
isListOpen: false,
});
};
Expand Down Expand Up @@ -964,6 +976,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 @@ -7,8 +7,8 @@
* 4. Using specificity to override panel shadow
*/
.euiComboBoxOptionsList {
// z-index is programmatically added to the options list by JavaScript
@include euiFormControlSize(auto, $includeAlternates: true); /* 3 */
z-index: $euiZComboBox;
position: absolute; /* 2 */
top: 0; /* 2 */

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
1 change: 0 additions & 1 deletion src/global_styling/variables/_z_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ $euiZContentMenu: $euiZLevel2;
$euiZNavigation: $euiZLevel4;
$euiZMask: $euiZLevel6;
$euiZModal: $euiZLevel8;
$euiZComboBox: $euiZModal + 1;
$euiZToastList: $euiZLevel9;