Skip to content

Commit e106ba6

Browse files
authored
Merge pull request #51 from HouseOfAngular/feat/add-hideOnEsc-global
2 parents 74af5a4 + 7346485 commit e106ba6

File tree

7 files changed

+47
-12
lines changed

7 files changed

+47
-12
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ variation looks like:
8787

8888
```ts
8989
export const tooltipVariation = {
90+
hideOnEscape: false,
9091
theme: null,
9192
arrow: false,
9293
animation: 'scale',

cypress/integration/helipopper.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,12 @@ describe('@ngneat/helipopper', () => {
9696
.get(popperSelector)
9797
.should('not.exist');
9898
});
99+
100+
it('should hide on Escape when variation have hideOnEscape property', () => {
101+
cy.get('.btn-container button[variation="hideOnEscape"]')
102+
.click({ force: true })
103+
.get(popperSelector)
104+
.should('not.exist');
105+
});
99106
});
100107
});

projects/ngneat/helipopper/src/lib/defaults.ts

+7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { TippyConfig } from './tippy.types';
22

33
type Variation = TippyConfig['variations'][0];
44

5+
const defaultsProps: Variation = {
6+
hideOnEscape: false
7+
};
8+
59
export const tooltipVariation: Variation = {
10+
...defaultsProps,
611
theme: null,
712
arrow: false,
813
animation: 'scale',
@@ -11,6 +16,7 @@ export const tooltipVariation: Variation = {
1116
};
1217

1318
export const popperVariation: Variation = {
19+
...defaultsProps,
1420
theme: 'light',
1521
arrow: true,
1622
offset: [0, 10],
@@ -21,6 +27,7 @@ export const popperVariation: Variation = {
2127

2228
export function withContextMenuVariation(baseVariation: Variation): Variation {
2329
return {
30+
...defaultsProps,
2431
...baseVariation,
2532
placement: 'right-start',
2633
trigger: 'manual',

projects/ngneat/helipopper/src/lib/tippy.directive.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ export class TippyDirective implements OnChanges, AfterViewInit, OnDestroy, OnIn
218218
onShow: instance => {
219219
this.zone.run(() => {
220220
this.instance.setContent(this.resolveContent());
221-
this.hideOnEscape && this.handleEscapeButton();
221+
if (this.hideOnEscape || this.props.hideOnEscape) {
222+
this.handleEscapeButton();
223+
}
222224
});
223225
if (this.useHostWidth) {
224226
// Don't access `hostWidth` multiple times since it's a getter that calls `getBoundingClientRect()`,

projects/ngneat/helipopper/src/lib/tippy.types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export const TIPPY_CONFIG = new InjectionToken<Partial<TippyConfig>>('Tippy conf
3131
export const TIPPY_REF = new InjectionToken('TIPPY_REF');
3232

3333
export type TippyInstance = Instance;
34-
export type TippyProps = Props;
34+
export interface TippyProps extends Props {
35+
hideOnEscape: boolean;
36+
}
3537

3638
export interface TippyConfig extends TippyProps {
3739
variations: Record<string, Partial<TippyProps>>;

src/app/app.component.html

+12
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,16 @@ <h6>Menu</h6>
262262
</ng-template>
263263
</div>
264264
</div>
265+
266+
<hr />
267+
268+
<div>
269+
<h6>Hide on Escape by global config</h6>
270+
271+
<div class="hideOnEscape btn-container">
272+
<button tippy="Press Escape Button" variation="hideOnEscape" class="btn btn-outline-secondary" type="button">
273+
Tooltip
274+
</button>
275+
</div>
276+
</div>
265277
</ng-container>

src/app/app.module.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { BrowserModule } from "@angular/platform-browser";
2-
import { NgModule } from "@angular/core";
1+
import { BrowserModule } from '@angular/platform-browser';
2+
import { NgModule } from '@angular/core';
33

4-
import { AppRoutingModule } from "./app-routing.module";
5-
import { AppComponent } from "./app.component";
6-
import { ReactiveFormsModule } from "@angular/forms";
7-
import { ExampleComponent } from "./example/example.component";
8-
import { popperVariation, TippyModule, tooltipVariation, withContextMenuVariation } from "@ngneat/helipopper";
4+
import { AppRoutingModule } from './app-routing.module';
5+
import { AppComponent } from './app.component';
6+
import { ReactiveFormsModule } from '@angular/forms';
7+
import { ExampleComponent } from './example/example.component';
8+
import { popperVariation, TippyModule, tooltipVariation, withContextMenuVariation } from '@ngneat/helipopper';
99

1010
@NgModule({
1111
declarations: [AppComponent, ExampleComponent],
@@ -14,20 +14,24 @@ import { popperVariation, TippyModule, tooltipVariation, withContextMenuVariatio
1414
AppRoutingModule,
1515
ReactiveFormsModule,
1616
TippyModule.forRoot({
17-
defaultVariation: "tooltip",
17+
defaultVariation: 'tooltip',
1818
variations: {
1919
tooltip: tooltipVariation,
2020
popper: popperVariation,
2121
menu: {
2222
...popperVariation,
23-
appendTo: "parent",
23+
appendTo: 'parent',
2424
arrow: false,
2525
offset: [0, 0]
2626
},
2727
contextMenu: withContextMenuVariation(popperVariation),
2828
popperBorder: {
2929
...popperVariation,
30-
theme: "light-border"
30+
theme: 'light-border'
31+
},
32+
hideOnEscape: {
33+
...tooltipVariation,
34+
hideOnEscape: true
3135
}
3236
}
3337
})

0 commit comments

Comments
 (0)