Skip to content

Commit 3330f34

Browse files
author
shleewhite
committed
fix: simplify logic for modal
1 parent c2dbfca commit 3330f34

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

packages/components/src/components/hds/flyout/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export default class HdsFlyout extends Component<HdsFlyoutSignature> {
150150
});
151151

152152
return () => {
153-
// if the <dialog> is removed from the dom while open we emulate the close event
153+
// if the <dialog> is removed from the dom while open we emulate the close event
154154
if (this._element && this._isOpen) {
155155
this._element.dispatchEvent(new Event('close'));
156156

@@ -163,8 +163,8 @@ export default class HdsFlyout extends Component<HdsFlyoutSignature> {
163163
}
164164

165165
document.removeEventListener('click', this._clickHandler, true);
166-
}
167-
});
166+
};
167+
});
168168

169169
@action
170170
willDestroyNode(): void {

packages/components/src/components/hds/modal/index.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import { action } from '@ember/object';
99
import { assert } from '@ember/debug';
1010
import { getElementId } from '../../../utils/hds-get-element-id.ts';
1111
import { buildWaiter } from '@ember/test-waiters';
12-
import { registerDestructor } from '@ember/destroyable';
1312
import { modifier } from 'ember-modifier';
1413

1514
import type { WithBoundArgs } from '@glint/template';
16-
import type Owner from '@ember/owner';
1715
import type { HdsModalSizes, HdsModalColors } from './types.ts';
1816

1917
import HdsDialogPrimitiveHeaderComponent from '../dialog-primitive/header.ts';
@@ -66,26 +64,6 @@ export default class HdsModal extends Component<HdsModalSignature> {
6664
private _bodyInitialOverflowValue = '';
6765
private _clickHandler!: (event: MouseEvent) => void;
6866

69-
constructor(owner: Owner, args: HdsModalSignature['Args']) {
70-
super(owner, args);
71-
72-
registerDestructor(this, (): void => {
73-
// if the <dialog> is removed from the dom while open we emulate the close event
74-
if (this._element && this._isOpen) {
75-
this._element.dispatchEvent(new Event('close'));
76-
77-
this._element.removeEventListener(
78-
'close',
79-
// eslint-disable-next-line @typescript-eslint/unbound-method
80-
this.registerOnCloseCallback,
81-
true
82-
);
83-
}
84-
85-
document.removeEventListener('click', this._clickHandler, true);
86-
});
87-
}
88-
8967
get isDismissDisabled(): boolean {
9068
return this.args.isDismissDisabled ?? false;
9169
}
@@ -211,6 +189,22 @@ export default class HdsModal extends Component<HdsModalSignature> {
211189
capture: true,
212190
passive: false,
213191
});
192+
193+
return () => {
194+
// if the <dialog> is removed from the dom while open we emulate the close event
195+
if (this._element && this._isOpen) {
196+
this._element.dispatchEvent(new Event('close'));
197+
198+
this._element.removeEventListener(
199+
'close',
200+
// eslint-disable-next-line @typescript-eslint/unbound-method
201+
this.registerOnCloseCallback,
202+
true
203+
);
204+
}
205+
206+
document.removeEventListener('click', this._clickHandler, true);
207+
};
214208
});
215209

216210
@action

0 commit comments

Comments
 (0)