Skip to content

Commit

Permalink
Keep post publishing popover open when a date is clicked (#29738)
Browse files Browse the repository at this point in the history
* Keep focus on the post schedule popover
Add a keepOpen prop to the DateTimePicker and keep focus on the date
picker popover when true.

* Document keepOpen prop
  • Loading branch information
allilevine authored Mar 15, 2021
1 parent 51a9128 commit e5a73b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/components/src/date-time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ This function will be called on each day, every time user browses into a differe

- Type: `Function`
- Required: No

### keepOpen

Whether focus should stay on the `DateTimePicker` after clicking on a date in the calendar.

- Type: `bool`
- Required: No
7 changes: 6 additions & 1 deletion packages/components/src/date-time/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DatePicker extends Component {
}

onChangeMoment( newDate ) {
const { currentDate, onChange } = this.props;
const { currentDate, onChange, keepOpen } = this.props;

// If currentDate is null, use now as momentTime to designate hours, minutes, seconds.
const momentDate = currentDate ? moment( currentDate ) : moment();
Expand All @@ -70,6 +70,11 @@ class DatePicker extends Component {
};

onChange( newDate.set( momentTime ).format( TIMEZONELESS_FORMAT ) );

// Keep focus on the date picker popover.
if ( keepOpen ) {
this.keepFocusInside();
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/date-time/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function DateTimePicker(
onMonthPreviewed,
onChange,
events,
keepOpen,
},
ref
) {
Expand All @@ -54,6 +55,7 @@ function DateTimePicker(
isInvalidDate={ isInvalidDate }
onMonthPreviewed={ onMonthPreviewed }
events={ events }
keepOpen={ keepOpen }
/>
</>
) }
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/post-schedule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function PostSchedule( { date, onUpdateDate } ) {
currentDate={ date }
onChange={ onChange }
is12Hour={ is12HourTime }
keepOpen={ true }
/>
);
}
Expand Down

0 comments on commit e5a73b7

Please sign in to comment.