Skip to content

Commit

Permalink
Change the matcher for instant tooltips from class to attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumluregn committed Oct 18, 2024
1 parent fe60e8e commit f2cd680
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions packages/ckeditor5-ui/src/tooltipmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ const BALLOON_CLASS = 'ck-tooltip';
*
* # Disabling tooltips
*
* In order to disable the tooltip temporarily, use the `data-cke-tooltip-disabled` attribute:
* In order to disable the tooltip temporarily, use the `data-cke-tooltip-disabled` attribute:
*
* ```ts
* domElement.dataset.ckeTooltipText = 'Disabled. For now.';
* domElement.dataset.ckeTooltipDisabled = 'true';
* ```
*
* # Instant tooltips
*
* To remove the delay before showing or hiding the tooltip, use the `data-cke-tooltip-instant` attribute:
*
* ```ts
* domElement.dataset.ckeTooltipInstant = 'true';
* ```
*
* # Styling tooltips
*
* By default, the tooltip has `.ck-tooltip` class and its text inner `.ck-tooltip__text`.
Expand Down Expand Up @@ -304,12 +312,12 @@ export default class TooltipManager extends /* #__PURE__ */ DomEmitterMixin() {
// The tooltip should be pinned immediately when the element gets focused using keyboard.
// If it is focused using the mouse, the tooltip should be pinned after a delay to prevent flashing.
// See https://github.com/ckeditor/ckeditor5/issues/16383
// Also, if the element has a class `ck-with-instant-tooltip`, the tooltip should be pinned immediately.
// Also, if the element has an attribute `data-cke-tooltip-instant`, the tooltip should be pinned immediately.
// This is useful for elements that have their content partially hidden (e.g. a long text in a small container)
// and should show a tooltip on hover, like merge field.
if (
if (
evt.name === 'focus' && !elementWithTooltipAttribute.matches( ':hover' ) ||
elementWithTooltipAttribute.matches( '.ck-with-instant-tooltip' )
elementWithTooltipAttribute.matches( '[data-cke-tooltip-instant]' )
) {
this._pinTooltip( elementWithTooltipAttribute, getTooltipData( elementWithTooltipAttribute ) );
} else {
Expand Down Expand Up @@ -337,6 +345,7 @@ export default class TooltipManager extends /* #__PURE__ */ DomEmitterMixin() {
// Do not hide the tooltip when the user moves the cursor over it.
if ( isEnteringBalloon ) {
this._unpinTooltipDebounced.cancel();

return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-ui/tests/tooltip/tooltipmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ describe( 'TooltipManager', () => {
} );
} );

it( 'should pin a tooltip instantly if element has a `ck-with-instant-tooltip` class', () => {
elements.a.classList.add( 'ck-with-instant-tooltip' );
it( 'should pin a tooltip instantly if element has a `data-cke-tooltip-instant` attribute', () => {
elements.a.dataset.ckeTooltipInstant = true;

utils.dispatchMouseEnter( elements.a );

Expand Down

0 comments on commit f2cd680

Please sign in to comment.