1
- import { AuButton } from ' @appuniversum/ember-appuniversum' ;
2
- import FloatingUiModifier from ' @appuniversum/ember-appuniversum/private/modifiers/floating-ui' ;
3
1
import { hash } from ' @ember/helper' ;
4
2
import { on } from ' @ember/modifier' ;
5
3
import { action } from ' @ember/object' ;
@@ -8,26 +6,41 @@ import { tracked } from '@glimmer/tracking';
8
6
import { focusTrap } from ' ember-focus-trap' ;
9
7
import { modifier } from ' ember-modifier' ;
10
8
import { ChevronDownIcon } from ' ./icons/chevron-down' ;
9
+ import AuButton from ' ./au-button' ;
10
+ import type { AuButtonSignature } from ' ./au-button' ;
11
+ import floatingUi from ' ../private/modifiers/floating-ui' ;
12
+
13
+ export interface AuDropdownSignature {
14
+ Args: {
15
+ alignment? : ' left' | ' right' ;
16
+ alert? : boolean ;
17
+ hideText? : boolean ;
18
+ icon? : AuButtonSignature [' Args' ][' icon' ];
19
+ iconAlignment? : AuButtonSignature [' Args' ][' iconAlignment' ];
20
+ onClose? : () => unknown ;
21
+ size? : AuButtonSignature [' Args' ][' size' ];
22
+ skin? : AuButtonSignature [' Args' ][' skin' ];
23
+ title? : string ;
24
+ };
25
+ Blocks: {
26
+ default: [];
27
+ };
28
+ Element: HTMLDivElement ;
29
+ }
11
30
12
- export default class AuDropdown extends Component {
13
- @tracked referenceElement = undefined ;
14
- @tracked arrowElement = undefined ;
31
+ export default class AuDropdown extends Component <AuDropdownSignature > {
32
+ // We use declare here, so TS doesn't consider `undefined` as part of the type since the initialisation happens after the constructor.
33
+ @tracked declare referenceElement: HTMLElement ;
34
+ @tracked declare arrowElement: HTMLElement ;
15
35
@tracked dropdownOpen = false ;
16
- floatingUi = FloatingUiModifier;
17
-
18
- reference = modifier (
19
- (element ) => {
20
- this .referenceElement = element;
21
- },
22
- { eager: false },
23
- );
24
-
25
- arrow = modifier (
26
- (element ) => {
27
- this .arrowElement = element;
28
- },
29
- { eager: false },
30
- );
36
+
37
+ reference = modifier ((element : HTMLElement ) => {
38
+ this .referenceElement = element ;
39
+ });
40
+
41
+ arrow = modifier ((element : HTMLElement ) => {
42
+ this .arrowElement = element ;
43
+ });
31
44
32
45
@action
33
46
openDropdown() {
@@ -50,8 +63,10 @@ export default class AuDropdown extends Component {
50
63
}
51
64
52
65
@action
53
- clickOutsideDeactivates (event ) {
54
- let isClosedByToggleButton = this .referenceElement .contains (event .target );
66
+ clickOutsideDeactivates(event : Event ) {
67
+ const isClosedByToggleButton = this .referenceElement ?.contains (
68
+ event .target as HTMLElement ,
69
+ );
55
70
56
71
if (! isClosedByToggleButton ) {
57
72
this .closeDropdown ();
@@ -113,7 +128,7 @@ export default class AuDropdown extends Component {
113
128
</AuButton >
114
129
{{#if this . dropdownOpen }}
115
130
<div
116
- {{this . floatingUi
131
+ {{floatingUi
117
132
this . referenceElement
118
133
this . arrowElement
119
134
defaultPlacement =this . alignment
0 commit comments