Skip to content

Commit

Permalink
fix(web-components): hides tooltips for navigation buttons on menu
Browse files Browse the repository at this point in the history
hides tooltips for top navigation icon buttons, when on popout menu

1267
  • Loading branch information
ad9242 authored and jd239 committed Jan 2, 2024
1 parent 0beaa5f commit 0ad0151
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class Button {

componentWillUpdate(): void {
this.loadingWidth();
this.setHasTooltip();
}

componentWillLoad(): void {
Expand All @@ -226,8 +227,7 @@ export class Button {

const id = this.el.id;
this.id = id !== undefined ? id : null;
this.hasTooltip =
!this.disableTooltip && (!!this.title || this.variant === "icon");
this.setHasTooltip();

if (!this.hasTooltip) {
const describedById = this.inheritedAttributes[
Expand Down Expand Up @@ -395,6 +395,11 @@ export class Button {
}
};

private setHasTooltip = (): void => {
this.hasTooltip =
!this.disableTooltip && (!!this.title || this.variant === "icon");
};

render() {
const TagType = (this.href && "a") || "button";
const { title, ariaLabel, inheritedAttributes } = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,43 @@ exports[`button component should test button as submit button on form 1`] = `
</ic-button>
`;

exports[`button component should test tooltip visibility changes when disable tooltip prop changes 1`] = `
<ic-button class="button-size-default button-variant-icon light" exportparts="button" id="test-button" variant="icon">
<mock:shadow-root>
<ic-tooltip id="ic-tooltip-ic-button-with-tooltip-test-button" label="Tooltip text" placement="bottom" target="ic-button-with-tooltip-test-button">
<button aria-describedby="ic-tooltip-ic-button-with-tooltip-test-button" aria-label="Tooltip text" class="button" part="button" type="button">
<slot></slot>
</button>
</ic-tooltip>
</mock:shadow-root>
Button
</ic-button>
`;

exports[`button component should test tooltip visibility changes when disable tooltip prop changes 2`] = `
<ic-button class="button-size-default button-variant-icon light" exportparts="button" id="test-button" variant="icon">
<mock:shadow-root>
<button aria-label="Tooltip text" class="button" part="button" type="button">
<slot></slot>
</button>
</mock:shadow-root>
Button
</ic-button>
`;

exports[`button component should test tooltip visibility changes when disable tooltip prop changes 3`] = `
<ic-button class="button-size-default button-variant-icon light" exportparts="button" id="test-button" variant="icon">
<mock:shadow-root>
<ic-tooltip id="ic-tooltip-ic-button-with-tooltip-test-button" label="Tooltip text" placement="bottom" target="ic-button-with-tooltip-test-button">
<button aria-describedby="ic-tooltip-ic-button-with-tooltip-test-button" aria-label="Tooltip text" class="button" part="button" type="button">
<slot></slot>
</button>
</ic-tooltip>
</mock:shadow-root>
Button
</ic-button>
`;

exports[`button component should update aria-expanded when attribute changed 1`] = `
<ic-button class="button-size-default button-variant-icon" exportparts="button" id="test-button" variant="icon">
<mock:shadow-root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,24 @@ describe("button component", () => {
expect(page.root).toMatchSnapshot();
});

it("should test tooltip visibility changes when disable tooltip prop changes", async () => {
const page = await newSpecPage({
components: [Button],
html: "<ic-button variant='icon' aria-label='Tooltip text' id='test-button'>Button</ic-button>",
});
expect(page.root).toMatchSnapshot();

page.root.disableTooltip = true;
await page.waitForChanges();

expect(page.root).toMatchSnapshot();

page.root.disableTooltip = false;
await page.waitForChanges();

expect(page.root).toMatchSnapshot();
});

it("should test blur handler", async () => {
const page = await newSpecPage({
components: [Button],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class NavigationButton {
this.initialAppearance;
let size: "default" | "large" = "large";
let fullWidth = false;
let disableTooltip = false;

if (this.mode === "menu") {
label = this.label;
Expand All @@ -145,6 +146,7 @@ export class NavigationButton {
size = "default";
fullWidth = true;
className = "popout-menu-button";
disableTooltip = true;
}

const buttonProps = {
Expand All @@ -157,6 +159,7 @@ export class NavigationButton {
download,
referrerpolicy,
fullWidth,
disableTooltip,
};

return (
Expand Down

0 comments on commit 0ad0151

Please sign in to comment.