Socket
Socket
Sign inDemoInstall

angular-simple-tooltip-test

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    angular-simple-tooltip-test

This package provides an Angular attribute directive and a service for showing tooltips declaratively or programmatically


Version published
Maintainers
1
Created

Readme

Source

Installation

npm i -S angular-simple-tooltip

Setting up

import { TooltipModule } from 'angular-simple-tooltip';

@Module({
    imports: [
        TooltipModule // Make `TooltipDirective` available in your module
    ]
})
export class YourModule {

}

Accessibility

The tooltip component that gets created handles wiring up aria-describedby attribute for accessability between the tooltip trigger and the tooltip content, so it's completely transparent to you as the API user.

Using TooltipDirective

TooltipModule exports an attribute directive called TooltipDirective that you can apply to any elements in your templates to trigger a tooltip on hover/keyboard navigation (when users focus on the tooltip trigger by pressing the tab key)/long presses on mobile devices. The followings are the @Input properties that TooltipDirective accepts

  • kunTooltip Configures the tooltip's content
  • kunTooltipPlacement Configures tooltip's placement, valid values are top, right, bottom, and left.

Available APIs

class TooltipDirective {

    @Input('kunTooltip')
    content: string;

    @Input('kunTooltipPlacement')
    placement: 'top' | 'right' | 'bottom' | 'left' = 'bottom';

}

Code example

import { Component } from '@angular/core';

@Component({
    selector: 'your-component',
    template: `
        <button
            kunTooltip='Hello World'
            <!-- if "kunTooltipPlacement" is not specified, "bottom" is assumed -->
            kunTooltipPlacement='bottom'>
            Hover over me!!!
        </button>
    `
})
export class YourComponent {

}

Result

Example 1


The tooltip also repositions itself to the top if it overflows the bottom edge of the viewport in case kunTooltipPlacement is bottom, similar behaviour also applies for the other placement values Example 2


The tooltip is also displayed when the trigger element receives keyboard focus when the user presses the tab key Example 3


On mobile devices, the user can activate the tooltip by long-pressing the trigger element Example 4


Using TooltipService

This package also exports a service called TooltipService that allows you to show tooltips programatically.

Available APIs

class TooltipService {

    /**
     * Programmatically show tooltip anchored at the element specified by `target`
     *
     * @param target The element at which to place the tooltip.
     * @param content Tooltip's body's content, it can contain HTML
     * @param placement Where the tooltip should be anchored at, `bottom` is the default
     */
    show(target: HTMLElement | SVGElement, content: string, placement?: 'top' | 'right' | 'bottom' | 'left'): void;

    /**
     * Show tooltip at a specific x/y location
     *
     * @param x The x location
     * @param y The y location
     * @param content Tooltip's body's content, it can contain HTML
     * @param placement Where the tooltip should be anchored at, `bottom` is the default
     */
    showAt(x: number, y: number, content: string, placement?: 'top' | 'right' | 'bottom' | 'left'): void;

    /**
     * Hide the currently active tooltip
     */
    hide(): void;

}

Code example

import { TooltipService } from 'angular-simple-tooltip';

@Component({
    selector: 'your-component',
    template: `
        <button
            type='button'
            (mouseover)='onShowTooltip($event.target)'
            (mouseout)='onHideTooltip()'>
            Hover over me!!!
        </button>
    `
})
export class YourComponent {

    constructor(private readonly _tooltipService: TooltipService) {

    }

    onShowTooltip(target: HTMLButtonElement) {
        this._tooltipService.show(target, 'Hello World');
    }

    onHideTooltip() {
        this._tooltipService.hide();
    }

}

The above example is very contrived, a better use case would be for when you need to manually create many <circle> and <path> SVG elements to render a network of some sort, and you need to display details about each node or edge when you hover over them, in this case, you can use TooltipService APIs to programatically show/hide tooltips on mouseover/mouseout.

Keywords

FAQs

Last updated on 06 Mar 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc