Skip to content

Commit

Permalink
DateTimePicker: fix onChange callback check so that it also works ins…
Browse files Browse the repository at this point in the history
…ide iframes (#54669)

* DateTimePicker: fix onChange callback check so that it also works inside iframes

* CHANGELOG
  • Loading branch information
ciampo authored Sep 21, 2023
1 parent bf757b7 commit 47e9e06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug fix

- `DateTimePicker`: fix onChange callback check so that it also works inside iframes ([#54669](https://github.com/WordPress/gutenberg/pull/54669)).

## 25.8.0 (2023-09-20)

### Enhancements
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/date-time/time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ export function TimePicker( {
method: 'hours' | 'minutes' | 'date' | 'year'
) => {
const callback: InputChangeCallback = ( value, { event } ) => {
if ( ! ( event.target instanceof HTMLInputElement ) ) {
// `instanceof` checks need to get the instance definition from the
// corresponding window object — therefore, the following logic makes
// the component work correctly even when rendered inside an iframe.
const HTMLInputElementInstance =
( event.target as HTMLInputElement )?.ownerDocument.defaultView
?.HTMLInputElement ?? HTMLInputElement;

if ( ! ( event.target instanceof HTMLInputElementInstance ) ) {
return;
}

Expand Down

0 comments on commit 47e9e06

Please sign in to comment.