|
1 | 1 | import Component from '@glimmer/component'; |
2 | 2 | import { tracked } from '@glimmer/tracking'; |
3 | 3 | import { action } from '@ember/object'; |
4 | | -import { scheduleOnce } from '@ember/runloop'; |
5 | 4 | import { service } from '@ember/service'; |
6 | 5 | import emberPowerCalendarDayClasses, { |
7 | 6 | type TDayClass, |
@@ -141,17 +140,16 @@ export default class PowerCalendarRangeDays extends Component<PowerCalendarRange |
141 | 140 | // Actions |
142 | 141 | @action |
143 | 142 | handleDayFocus(e: FocusEvent): void { |
144 | | - scheduleOnce( |
145 | | - 'actions', |
146 | | - this, |
147 | | - this._updateFocused.bind(this), |
148 | | - (e.target as HTMLElement).dataset['date'], |
149 | | - ); |
| 143 | + queueMicrotask(() => { |
| 144 | + this._updateFocused((e.target as HTMLElement).dataset['date']); |
| 145 | + }); |
150 | 146 | } |
151 | 147 |
|
152 | 148 | @action |
153 | 149 | handleDayBlur(): void { |
154 | | - scheduleOnce('actions', this, this._updateFocused.bind(this), null); |
| 150 | + queueMicrotask(() => { |
| 151 | + this._updateFocused(null); |
| 152 | + }); |
155 | 153 | } |
156 | 154 |
|
157 | 155 | @action |
@@ -200,13 +198,9 @@ export default class PowerCalendarRangeDays extends Component<PowerCalendarRange |
200 | 198 | } |
201 | 199 |
|
202 | 200 | this.focusedId = day.id; |
203 | | - scheduleOnce( |
204 | | - 'afterRender', |
205 | | - this, |
206 | | - focusDate, |
207 | | - this.args.calendar.uniqueId, |
208 | | - this.focusedId ?? '', |
209 | | - ); |
| 201 | + queueMicrotask(() => { |
| 202 | + focusDate(this.args.calendar.uniqueId, this.focusedId ?? ''); |
| 203 | + }); |
210 | 204 | } |
211 | 205 |
|
212 | 206 | @action |
@@ -234,22 +228,19 @@ export default class PowerCalendarRangeDays extends Component<PowerCalendarRange |
234 | 228 | this.lastKeyDownWasSpace = false; |
235 | 229 | } |
236 | 230 |
|
237 | | - setup = modifier( |
238 | | - () => { |
239 | | - if (this.didSetup) { |
240 | | - return; |
241 | | - } |
| 231 | + setup = modifier(() => { |
| 232 | + if (this.didSetup) { |
| 233 | + return; |
| 234 | + } |
242 | 235 |
|
243 | | - this.didSetup = true; |
| 236 | + this.didSetup = true; |
244 | 237 |
|
| 238 | + if (this.args.autofocus) { |
245 | 239 | if (this.args.autofocus) { |
246 | | - scheduleOnce('afterRender', this, this.initialFocus.bind(this)); |
| 240 | + queueMicrotask(() => this.initialFocus()); |
247 | 241 | } |
248 | | - }, |
249 | | - // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
250 | | - // @ts-ignore |
251 | | - { eager: false }, |
252 | | - ); |
| 242 | + } |
| 243 | + }); |
253 | 244 |
|
254 | 245 | initialFocus() { |
255 | 246 | const activeDay = this.days.find((x) => x.isSelected && !x.isDisabled); |
@@ -298,13 +289,9 @@ export default class PowerCalendarRangeDays extends Component<PowerCalendarRange |
298 | 289 | this.focusedId = formatDate(date, 'YYYY-MM-DD'); |
299 | 290 |
|
300 | 291 | if (step !== 0) { |
301 | | - scheduleOnce( |
302 | | - 'afterRender', |
303 | | - this, |
304 | | - focusDate, |
305 | | - this.args.calendar.uniqueId, |
306 | | - this.focusedId ?? '', |
307 | | - ); |
| 292 | + queueMicrotask(() => { |
| 293 | + focusDate(this.args.calendar.uniqueId, this.focusedId ?? ''); |
| 294 | + }); |
308 | 295 | } else { |
309 | 296 | focusDate(this.args.calendar.uniqueId, this.focusedId ?? ''); |
310 | 297 | } |
|
0 commit comments