Skip to content

Commit a5e1601

Browse files
authored
fix: only show toolbar button tooltip on keyboard focus (#10040)
1 parent 8fbd11b commit a5e1601

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

packages/rich-text-editor/src/vaadin-rich-text-editor-mixin.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* license.
1010
*/
1111
import '../vendor/vaadin-quill.js';
12+
import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
1213
import { timeOut } from '@vaadin/component-base/src/async.js';
1314
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
1415
import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js';
@@ -425,13 +426,16 @@ export const RichTextEditorMixin = (superClass) =>
425426
}
426427

427428
/** @private */
428-
__showTooltip(event) {
429-
const target = event.target;
429+
__showTooltip({ type, target }) {
430+
// Only show tooltip when focused with keyboard
431+
if (type === 'focusin' && !isKeyboardActive()) {
432+
return;
433+
}
430434
this._tooltip.target = target;
431435
this._tooltip.text = target.ariaLabel;
432436
this._tooltip._stateController.open({
433-
focus: event.type === 'focusin',
434-
hover: event.type === 'mouseenter',
437+
focus: type === 'focusin',
438+
hover: type === 'mouseenter',
435439
});
436440
}
437441

packages/rich-text-editor/test/toolbar.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
focusout,
88
isDesktopSafari,
99
isFirefox,
10+
mousedown,
1011
nextRender,
1112
nextUpdate,
1213
oneEvent,
@@ -640,7 +641,10 @@ describe('toolbar controls', () => {
640641
expect(overlay.opened).to.be.false;
641642
});
642643

643-
it('should open tooltip when focusing toolbar button', () => {
644+
it('should open tooltip when focusing toolbar button with keyboard', () => {
645+
// Mimic keyboard focus
646+
esc(rte);
647+
644648
const undo = getButton('undo');
645649
undo.focus();
646650

@@ -649,7 +653,18 @@ describe('toolbar controls', () => {
649653
expect(overlay.opened).to.be.true;
650654
});
651655

656+
it('should not open tooltip when focusing toolbar button with mouse', () => {
657+
const undo = getButton('undo');
658+
mousedown(undo);
659+
undo.focus();
660+
661+
expect(overlay.opened).to.be.false;
662+
});
663+
652664
it('should move tooltip when focusing other toolbar button', () => {
665+
// Mimic keyboard focus
666+
esc(rte);
667+
653668
const undo = getButton('undo');
654669
undo.focus();
655670

@@ -662,6 +677,9 @@ describe('toolbar controls', () => {
662677
});
663678

664679
it('should close tooltip when focus is moved away from toolbar button', () => {
680+
// Mimic keyboard focus
681+
esc(rte);
682+
665683
const undo = getButton('undo');
666684
undo.focus();
667685

0 commit comments

Comments
 (0)