-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
feat(material/tooltip): add isDisabled method to tooltip harness #27038
feat(material/tooltip): add isDisabled method to tooltip harness #27038
Conversation
@@ -52,6 +52,11 @@ export abstract class _MatTooltipHarnessBase extends ComponentHarness { | |||
return !!panel && !(await panel.hasClass(this._hiddenClass)); | |||
} | |||
|
|||
/** Gets whether the tooltip is disabled */ | |||
async isDisabled(): Promise<boolean> { | |||
return !(await this._optionalPanel()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be true
if the user did not first call show()
? Perhaps this method should attempt to show the tooltip, see if it's there, then hide it afterwards in case it wasn't disabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you're right. 👍
Btw, the reason I didn't call show()
inside here is because I saw a method like getTooltipText()
requires the user to call show()
, otherwise it will return an empty string.(maybe getTooltipText()
should also handle show/hide in itself to provide better DX)
@@ -52,6 +52,11 @@ export abstract class _MatTooltipHarnessBase extends ComponentHarness { | |||
return !!panel && !(await panel.hasClass(this._hiddenClass)); | |||
} | |||
|
|||
/** Gets whether the tooltip is disabled */ | |||
async isDisabled(): Promise<boolean> { | |||
return !(await this._optionalPanel()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't tell you that the tooltip is disabled, it tells you whether it's opened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at tooltip.ts
and that's the only way I could think of to find out about the disabled
state.
https://github.com/angular/components/blob/main/src/material/tooltip/tooltip.ts#L420
You are right in a sense that even if the tooltip isn't disabled but has an empty message, this method will return true
.
But I think it's kinda correct to return true
in that case too. cause at the end, a tooltip with an empty message also acts like a disabled
one and doesn't have a different behavior.
Can you think of any other way to handle it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually the way we'd handle it is to add something to the DOM (e.g. a class) that reflects the disabled state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look please.
52214e9
to
d3218cf
Compare
d3218cf
to
24e204e
Compare
src/material/tooltip/tooltip.ts
Outdated
@@ -222,8 +225,10 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase> | |||
// If tooltip is disabled, hide immediately. | |||
if (this._disabled) { | |||
this.hide(0); | |||
this._elementRef.nativeElement.classList.add(`${this._cssClassPrefix}-${DISABLED_CLASS}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done through the host
bindings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
24e204e
to
d2c0362
Compare
You need to run |
d2c0362
to
a22cfaa
Compare
e105897
to
705bf60
Compare
705bf60
to
09d441e
Compare
@crisbeto I ran the |
The |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
closes #27016.