Skip to content

Commit f98d974

Browse files
authored
Merge pull request #2522 from RoboErikG/date-field-pos
fix: Wait for an animation frame before showing the date picker
2 parents 21b7dd0 + e3b1054 commit f98d974

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

plugins/field-date/src/field_date.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,17 @@ export class FieldDate extends Blockly.FieldTextInput {
142142
if (!this.htmlInput_) return;
143143
Blockly.utils.dom.addClass(this.htmlInput_, 'blocklyDateInput');
144144

145-
// NOTE: HTMLInputElement.showPicker() is not available in earlier
146-
// TypeScript versions (like 4.7.4), so casting to `any` to be compatible
147-
// with dev scripts. Additionally, it's not available for date inputs for
148-
// Safari. For browser compatibility of showPicker, see:
149-
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/showPicker
150-
/* eslint-disable @typescript-eslint/no-explicit-any */
151-
(this.htmlInput_ as any).showPicker();
152-
/* eslint-enable @typescript-eslint/no-explicit-any */
145+
// Delay showing the picker until the editor has a chance to position
146+
window.requestAnimationFrame(() => {
147+
// NOTE: HTMLInputElement.showPicker() is not available in earlier
148+
// TypeScript versions (like 4.7.4), so casting to `any` to be compatible
149+
// with dev scripts. Additionally, it's not available for date inputs for
150+
// Safari. For browser compatibility of showPicker, see:
151+
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/showPicker
152+
/* eslint-disable @typescript-eslint/no-explicit-any */
153+
(this.htmlInput_ as any).showPicker();
154+
/* eslint-enable @typescript-eslint/no-explicit-any */
155+
});
153156
}
154157

155158
/**

0 commit comments

Comments
 (0)