Skip to content

feature request : add ability to suppress tooltip on focus. #4

@monkeyhouse

Description

@monkeyhouse

I'd like like the ability to not show the tooltip when a user focuses an input or button eg : via keyboard, or after it is pressed. But, I want it to still display when the user uses the mouse to hover over or click the input and/or button.

Explanation :
Normally, I like the default behavior - when the user focuses on an element, the tooltip shows. This is great. But I want the ability to disable it for some elements, because, sometimes I need the tooltip to respond to the mouse only.

Is this something you are interested in implementing or should I fork it?

Implementation Strategy :

In file projects/ng2-tooltip-directive/src/lib/tooltip.directive.ts (1) split the mouse enter method into onMouseEnter and onFocusIn into two seperate methods (2) add isDisplayOnFocus getter and (3) add a focusTigger option ( minor modifications in a few files )

@HostListener('mouseenter')
onMouseEnter() {
    if (this.isDisplayOnHover == false) {
        return;
    }

    this.show();
}



@HostListener('focusin')
onFocusIn() {
    if (this.isDisplayOnFocus == false) {
        return;
    }

    this.show();
}

get isDisplayOnFocus(): boolean {
    if (this.options['display'] == false) {
        return false;
    }

    if (this.options['displayTouchscreen'] == false && this.isTouchScreen) {
        return false;
    }

    if (this.options['focusTigger'] === false ) {
        return false;
    }

    return true;
}

options.ts
->
defaultOptions = {
...
focusTrigger : true
}

options.interface.ts
export interface TooltipOptions = {
...
focusTrigger? : boolean
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions