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

Tooltip error thrown when switching the disabled state for a cds-icon-button from true to false. #3049

Open
koenvd opened this issue Nov 6, 2024 · 4 comments

Comments

@koenvd
Copy link
Contributor

koenvd commented Nov 6, 2024

To reproduce create a template containing this:

<cds-tooltip [autoAlign]="true" [description]="description">
   <cds-icon-button [disabled]="disabled">
   </cds-icon-button>
</cds-tooltip>

Then switch disabled to true. Then to false. At that moment the following error is thrown:
Image

Location where it fails:
Image

In both cases (enabled and disabled) the tooltip still renders fine though. But somehow the Tooltip doesn't find the popover content when switching to the enabled state.

Fix can be to just play safe and only call setAttribute when the popover content was found. So in tooltip.component.ts just do

this.popoverContentRef = this.elementRef.nativeElement.querySelector(".cds--popover-content");
this.popoverContentRef?.setAttribute("style", "");

But I think something more fundamental is going wrong if I read the comments above those lines.

Probably there's a better fix?

@Akshat55
Copy link
Contributor

Akshat55 commented Nov 8, 2024

@koenvd What you're currently doing is wrapping a tooltip within a tooltip and I believe that is causing this issue. For accessibility purpose, starting v11, cds-icon-button component is wrapped in cds-tooltip.

To resolve this, you can change the above code to the following:

<cds-icon-button
   [disabled]="disabled"
   [autoAlign]="true"
   [description]="description">
   <svg class="cds--btn__icon" cdsIcon="copy" size="16"></svg>
</cds-icon-button>

@koenvd
Copy link
Contributor Author

koenvd commented Nov 15, 2024

Indeed that resolves the error @Akshat55 .

But I noticed before the tooltip was appearing when the button was disabled. So we could explain in the tooltip why the button was disabled. Now the tooltip is not appearing when the button is disabled.

Not sure there's a way to do that?

@Akshat55
Copy link
Contributor

But I noticed before the tooltip was appearing when the button was disabled. So we could explain in the tooltip why the button was disabled. Now the tooltip is not appearing when the button is disabled.

@koenvd, that is the current behavior defined in Carbon. I'll see if I can add a showTooltipWhenDisabled flag so you can show the tooltip!

@Akshat55 Akshat55 added the component: Button For Button issues label Nov 15, 2024
@koenvd
Copy link
Contributor Author

koenvd commented Nov 15, 2024

That would be nice. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants