Skip to content

Commit

Permalink
fix(tooltip): Prevent tooltip from appearing above modal overlay (#5873)
Browse files Browse the repository at this point in the history
**Related Issue:** #5388

## Summary

fix(tooltip): Prevent tooltip from appearing above modal overlay. #5388

- Updates floating-ui to use tailwind configuration
- Sets default z-index to be that of a dropdown
- Adds ability for users to customize zindex of tooltips and popovers
  - CSS vars `--calcite-tooltip-z-index` and `--calcite-popover-z-index`

```html
 <calcite-tooltip style="--calcite-tooltip-z-index: 500;" label="Open modal" reference-element="button">
Open modal
</calcite-tooltip>
```
  • Loading branch information
driskull authored Dec 5, 2022
1 parent 88eaee5 commit f7a5de2
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/assets/styles/_floating-ui.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ $floating-ui-transform-bottom: translateY(-5px);
$floating-ui-transform-top: translateY(5px);
$floating-ui-transform-left: translateX(5px);
$floating-ui-transform-right: translateX(-5px);
$floating-ui-default-z-index: 900;

:root {
--calcite-floating-ui-transition: var(--calcite-animation-timing);
--calcite-floating-ui-z-index: theme("zIndex.dropdown");
}

@mixin floatingUIAnim {
Expand Down Expand Up @@ -74,10 +74,10 @@ $floating-ui-default-z-index: 900;
}
}

@mixin floatingUIContainer($zIndex: $floating-ui-default-z-index) {
@mixin floatingUIContainer() {
display: block;
position: absolute;
z-index: $zIndex;
z-index: var(--calcite-floating-ui-z-index);
}

@mixin floatingUIWrapper {
Expand All @@ -88,9 +88,9 @@ $floating-ui-default-z-index: 900;
visibility: visible;
}

@mixin floatingUIHost($zIndex: $floating-ui-default-z-index) {
@mixin floatingUIHost() {
:host {
@include floatingUIContainer($zIndex);
@include floatingUIContainer();
}

@include floatingUIHostAnim();
Expand Down
1 change: 1 addition & 0 deletions src/components/combobox/combobox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
}

.floating-ui-container {
--calcite-floating-ui-z-index: theme("zIndex.dropdown");
@include floatingUIContainer();
@include floatingUIWrapper();
}
Expand Down
1 change: 1 addition & 0 deletions src/components/dropdown/dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@include disabled();

:host .calcite-dropdown-wrapper {
--calcite-floating-ui-z-index: theme("zIndex.dropdown");
@include floatingUIContainer();
@include floatingUIWrapper();
}
Expand Down
1 change: 1 addition & 0 deletions src/components/input-date-picker/input-date-picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
}

.menu-container {
--calcite-floating-ui-z-index: theme("zIndex.dropdown");
@include floatingUIContainer();
@include floatingUIWrapper();
@apply invisible;
Expand Down
21 changes: 21 additions & 0 deletions src/components/modal/modal.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,24 @@ export const darkThemeRTLCustomSize_TestOnly = (): string => html`
`;

darkThemeRTLCustomSize_TestOnly.parameters = { themes: themesDarkDefault };

export const withTooltips_TestOnly = (): string => html`
<button id="button">Open</button>
<calcite-tooltip style="--calcite-tooltip-z-index: 600;" open label="Open modal" reference-element="button"
>Open modal</calcite-tooltip
>
<calcite-modal open aria-labelledby="modal-title" id="modal">
<div slot="header" id="modal-title">Modal title</div>
<div slot="content">
Modal content lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</div>
<calcite-button id="back-button-modal" slot="back" color="neutral" icon="chevron-left" width="full"
>Back
</calcite-button>
<calcite-button slot="secondary" width="full" appearance="outline">Cancel</calcite-button>
<calcite-button slot="primary" width="full">Save</calcite-button>
</calcite-modal>
<calcite-tooltip open label="Back" reference-element="back-button-modal">Back</calcite-tooltip>
`;
12 changes: 12 additions & 0 deletions src/components/popover/popover.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-popover-z-index: Sets the z-index value for the component.
*/

:host {
--calcite-floating-ui-z-index: var(--calcite-popover-z-index, theme("zIndex.popover"));
}

@include floatingUIHost();
@include floatingUIArrow();

Expand Down
4 changes: 2 additions & 2 deletions src/components/tooltip/tooltip.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("calcite-tooltip", () => {
}
]));

it("should have zIndex of 999", async () => {
it("should have zIndex of 901", async () => {
const page = await newE2EPage();

await page.setContent(
Expand All @@ -62,7 +62,7 @@ describe("calcite-tooltip", () => {

const style = await tooltip.getComputedStyle();

expect(style.zIndex).toBe("999");
expect(style.zIndex).toBe("901");
});

it("tooltip positions when referenceElement is set", async () => {
Expand Down
14 changes: 13 additions & 1 deletion src/components/tooltip/tooltip.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
@include floatingUIHost(999);
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-tooltip-z-index: Sets the z-index value for the component.
*/

:host {
--calcite-floating-ui-z-index: var(--calcite-tooltip-z-index, theme("zIndex.tooltip"));
}

@include floatingUIHost();
@include floatingUIArrow();

.container {
Expand Down
3 changes: 2 additions & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ export default {
dropdown: "600",
overlay: "700",
modal: "800",
popup: "900"
popover: "900",
tooltip: "901"
}
}
},
Expand Down

0 comments on commit f7a5de2

Please sign in to comment.