Skip to content

Commit

Permalink
fix(tooltip): tooltip does not appear when ... (ios) ng-bootstrap#3630
Browse files Browse the repository at this point in the history
  • Loading branch information
gpolychronis committed Mar 13, 2020
1 parent fdba58a commit fa1648b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/tooltip/tooltip-config.spec.ts
Expand Up @@ -6,7 +6,7 @@ describe('ngb-tooltip-config', () => {

expect(config.autoClose).toBe(true);
expect(config.placement).toBe('auto');
expect(config.triggers).toBe('hover focus');
expect(config.triggers).toBe('hover focus pointerdown:dummy');
expect(config.container).toBeUndefined();
expect(config.disableTooltip).toBe(false);
expect(config.tooltipClass).toBeUndefined();
Expand Down
2 changes: 1 addition & 1 deletion src/tooltip/tooltip-config.ts
Expand Up @@ -11,7 +11,7 @@ import {PlacementArray} from '../util/positioning';
export class NgbTooltipConfig {
autoClose: boolean | 'inside' | 'outside' = true;
placement: PlacementArray = 'auto';
triggers = 'hover focus';
triggers = 'hover focus pointerdown:dummy';
container: string;
disableTooltip = false;
tooltipClass: string;
Expand Down
18 changes: 2 additions & 16 deletions src/util/autoclose.ts
Expand Up @@ -10,26 +10,12 @@ const isContainedIn = (element: HTMLElement, array?: HTMLElement[]) =>
const matchesSelectorIfAny = (element: HTMLElement, selector?: string) =>
!selector || closest(element, selector) != null;

// we have to add a more significant delay to avoid re-opening when handling (click) on a toggling element
// TODO: use proper Angular platform detection when NgbAutoClose becomes a service and we can inject PLATFORM_ID
const isMobile = (() => {
const isIOS = () => /iPad|iPhone|iPod/.test(navigator.userAgent) ||
(/Macintosh/.test(navigator.userAgent) && navigator.maxTouchPoints && navigator.maxTouchPoints > 2);
const isAndroid = () => /Android/.test(navigator.userAgent);

return typeof navigator !== 'undefined' ? !!navigator.userAgent && (isIOS() || isAndroid()) : false;
})();

// setting 'ngbAutoClose' synchronously on mobile results in immediate popup closing
// when tapping on the triggering element
const wrapAsyncForMobile = fn => isMobile ? () => setTimeout(() => fn(), 100) : fn;

export function ngbAutoClose(
zone: NgZone, document: any, type: boolean | 'inside' | 'outside', close: () => void, closed$: Observable<any>,
insideElements: HTMLElement[], ignoreElements?: HTMLElement[], insideSelector?: string) {
// closing on ESC and outside clicks
if (type) {
zone.runOutsideAngular(wrapAsyncForMobile(() => {
zone.runOutsideAngular(() => {

const shouldCloseOnClick = (event: MouseEvent) => {
const element = event.target as HTMLElement;
Expand Down Expand Up @@ -64,6 +50,6 @@ export function ngbAutoClose(


race<Event>([escapes$, closeableClicks$]).subscribe(() => zone.run(close));
}));
});
}
}

0 comments on commit fa1648b

Please sign in to comment.