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

fix(web-components): hides tooltips for navigation buttons on menu #1344

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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