@@ -3,7 +3,6 @@ import { tracked } from '@glimmer/tracking';
33import { action } from ' @ember/object' ;
44import { guidFor } from ' @ember/object/internals' ;
55import calculatePosition from ' ../utils/calculate-position.ts' ;
6- import { schedule } from ' @ember/runloop' ;
76import { hash } from ' @ember/helper' ;
87import BasicDropdownTrigger from ' ./basic-dropdown-trigger.gts' ;
98import BasicDropdownContent from ' ./basic-dropdown-content.gts' ;
@@ -27,7 +26,6 @@ import type {
2726 TRootEventType ,
2827} from ' ../types.ts' ;
2928
30- const UNINITIALIZED = {};
3129const IGNORED_STYLES = [' top' , ' left' , ' right' , ' width' , ' height' ];
3230
3331export interface BasicDropdownDefaultBlock <
@@ -122,35 +120,44 @@ export default class BasicDropdown<
122120 @tracked width: string | undefined ;
123121 @tracked height: string | undefined ;
124122 @tracked otherStyles: Record <string , string | number | undefined > = {};
125- @tracked isOpen = this .args .initiallyOpened || false ;
126123 @tracked renderInPlace =
127124 this .args .renderInPlace !== undefined ? this .args .renderInPlace : false ;
125+ @tracked private _isOpen = this .args .initiallyOpened || false ;
126+
128127 private previousVerticalPosition? : VerticalPosition | undefined ;
129128 private previousHorizontalPosition? : HorizontalPosition | undefined ;
130129 private triggerElement: HTMLElement | null = null ;
131130 private dropdownElement: HTMLElement | null = null ;
132131
133132 private _uid = guidFor (this );
134133 private _dropdownId: string = ` ember-basic-dropdown-content-${this ._uid } ` ;
135- private _previousDisabled = UNINITIALIZED ;
136134 private _actions: DropdownActions = {
137135 open: this .open .bind (this ),
138136 close: this .close .bind (this ),
139137 toggle: this .toggle .bind (this ),
140138 reposition: this .reposition .bind (this ),
139+ updatePublicApi: this .updatePublicApi .bind (this ),
141140 registerTriggerElement: this .registerTriggerElement .bind (this ),
142141 registerDropdownElement: this .registerDropdownElement .bind (this ),
143142 getTriggerElement : () => this .triggerElement ,
144143 };
145144
146- private get horizontalPosition() {
145+ private get horizontalPosition(): HorizontalPosition {
147146 return this .args .horizontalPosition || ' auto' ; // auto-right | right | center | left
148147 }
149148
150- private get verticalPosition() {
149+ private get verticalPosition(): VerticalPosition {
151150 return this .args .verticalPosition || ' auto' ; // above | below
152151 }
153152
153+ get isOpen(): boolean {
154+ return ! this .disabled && this ._isOpen ;
155+ }
156+
157+ set isOpen(v : boolean ) {
158+ this ._isOpen = v ;
159+ }
160+
154161 get destination(): string {
155162 return this .args .destination || this ._getDestinationId ();
156163 }
@@ -179,25 +186,7 @@ export default class BasicDropdown<
179186 }
180187
181188 get disabled(): boolean {
182- const newVal = this .args .disabled || false ;
183- if (
184- this ._previousDisabled !== UNINITIALIZED &&
185- this ._previousDisabled !== newVal
186- ) {
187- // eslint-disable-next-line ember/no-runloop
188- schedule (' actions' , () => {
189- if (newVal && this .publicAPI .isOpen ) {
190- // eslint-disable-next-line ember/no-side-effects
191- this .isOpen = false ;
192- }
193- if (this .args .registerAPI ) {
194- this .args .registerAPI (this .publicAPI );
195- }
196- });
197- }
198- // eslint-disable-next-line ember/no-side-effects
199- this ._previousDisabled = newVal ;
200- return newVal ;
189+ return this .args .disabled || false ;
201190 }
202191
203192 get publicAPI(): Dropdown {
@@ -337,6 +326,15 @@ export default class BasicDropdown<
337326 return this .applyReposition (triggerElement , dropdownElement , positionData );
338327 }
339328
329+ @action
330+ updatePublicApi() {
331+ if (! this .args .registerAPI ) {
332+ return ;
333+ }
334+
335+ this .args .registerAPI (this .publicAPI );
336+ }
337+
340338 @action
341339 registerTriggerElement(element : HTMLElement ): void {
342340 this .triggerElement = element ;
0 commit comments