fix(tooltip): hide tooltip if the invoker gets disabled (#2154)
This commit is contained in:
parent
40a4e13736
commit
d997e5233e
3 changed files with 37 additions and 4 deletions
5
.changeset/fifty-nails-cry.md
Normal file
5
.changeset/fifty-nails-cry.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/ui': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
[tooltip] hide tooltip if the invoker gets disabled
|
||||||
|
|
@ -32,15 +32,13 @@ export function withHoverInteraction({ delayIn = 0, delayOut = 300 }) {
|
||||||
*/
|
*/
|
||||||
function handleOpenClosed(event) {
|
function handleOpenClosed(event) {
|
||||||
const { type } = event;
|
const { type } = event;
|
||||||
if (controller._hasDisabledInvoker()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
clearTimeout(delayTimeout);
|
clearTimeout(delayTimeout);
|
||||||
isFocused = type === 'focusout' ? false : isFocused || type === 'focusin';
|
isFocused = type === 'focusout' ? false : isFocused || type === 'focusin';
|
||||||
isHovered = type === 'mouseleave' ? false : isHovered || type === 'mouseenter';
|
isHovered = type === 'mouseleave' ? false : isHovered || type === 'mouseenter';
|
||||||
const shouldOpen = isFocused || isHovered;
|
const shouldOpen = isFocused || isHovered;
|
||||||
|
|
||||||
if (shouldOpen) {
|
if (shouldOpen && !controller._hasDisabledInvoker()) {
|
||||||
delayTimeout = setTimeout(() => {
|
delayTimeout = setTimeout(() => {
|
||||||
controller.show();
|
controller.show();
|
||||||
}, delayIn);
|
}, delayIn);
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,36 @@ describe('lion-tooltip', () => {
|
||||||
expect(el._overlayCtrl.isShown).to.equal(false);
|
expect(el._overlayCtrl.isShown).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('gets hidden when invoker gets disabled', async () => {
|
||||||
|
const el = /** @type {LionTooltip} */ (
|
||||||
|
await fixture(html`
|
||||||
|
<lion-tooltip>
|
||||||
|
<div slot="content">Hey there</div>
|
||||||
|
<button slot="invoker">Tooltip button</button>
|
||||||
|
</lion-tooltip>
|
||||||
|
`)
|
||||||
|
);
|
||||||
|
const invoker = /** @type {HTMLButtonElement} */ (
|
||||||
|
Array.from(el.children).find(child => child.slot === 'invoker')
|
||||||
|
);
|
||||||
|
const eventFocusIn = new Event('focusin');
|
||||||
|
invoker.dispatchEvent(eventFocusIn);
|
||||||
|
clock.tick(300);
|
||||||
|
await el.updateComplete;
|
||||||
|
// @ts-expect-error [allow-protected-in-tests]
|
||||||
|
expect(el._overlayCtrl.isShown).to.equal(true);
|
||||||
|
|
||||||
|
invoker.setAttribute('disabled', '');
|
||||||
|
|
||||||
|
const eventFocusOut = new Event('focusout');
|
||||||
|
invoker.dispatchEvent(eventFocusOut);
|
||||||
|
clock.tick(300);
|
||||||
|
await el.updateComplete;
|
||||||
|
await el.updateComplete; // webkit needs longer
|
||||||
|
// @ts-expect-error [allow-protected-in-tests]
|
||||||
|
expect(el._overlayCtrl.isShown).to.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('contains html when specified in tooltip content body', async () => {
|
it('contains html when specified in tooltip content body', async () => {
|
||||||
const el = /** @type {LionTooltip} */ (
|
const el = /** @type {LionTooltip} */ (
|
||||||
await fixture(html`
|
await fixture(html`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue