-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datepicker: Add isInvalidDay support #12962
Datepicker: Add isInvalidDay support #12962
Conversation
4269e8f
to
912ca49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me, just one minor comment.
@@ -36,7 +36,7 @@ class DatePicker extends Component { | |||
} | |||
|
|||
render() { | |||
const { currentDate } = this.props; | |||
const { currentDate, isInvalidDay } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not totally required but should we provide a default prop for this of false
just to be extra explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @timmyc !
I could set a default prop or just { isInvalidDay = false } = this.props
, but I think its best to pass along an undefined
value to react-dates's own default prop for isOutsideRange
:
The reason is because React handles an undefined
prop differently than null
or possibly false
(https://reactjs.org/docs/react-component.html#defaultprops).
912ca49
to
caa76ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DateTime component has a README.md . The prop should be documented.
757ec8d
to
33d6217
Compare
Thanks for the review @aduth. Changes made to DateTime Readme. |
Moment is not otherwise exposed as part of the public interface, and I don't think we'd want to start now (related: #11418). What would you think about passing the |
@aduth I've modified how I updated the test instructions on this PR. Thanks again for the input. |
@@ -36,7 +36,7 @@ class DatePicker extends Component { | |||
} | |||
|
|||
render() { | |||
const { currentDate } = this.props; | |||
const { currentDate, isInvalidDay } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm nitpicking at this point, but the term "Day" is ambiguous to me, where the value itself to check is a Date
object. I'm also a bit wary about the negation here, regardless of what react-dates
is doing, since it seems a bit unnecessary to reverse what is essentially a validity check.
Thoughts on isValidDate
instead?
There's a further argument about the naming of the prop implying that its value is itself a boolean, when in fact it's a callback function. I'm not sure what precedent there is here for these sorts of callback functions. I'm not overly concerned about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also a bit wary about the negation here, regardless of what react-dates is doing, since it seems a bit unnecessary to reverse what is essentially a validity check.
One advantage of the negation relates to the optionality of the prop. By default, all dates are valid. It would seem odd to me that by adding a positively-framed check, isValidDate
, I'd have to explicitly return true to enable a date that is otherwise enabled by default.
the term "Day" is ambiguous to me
Great point.
My slight preference is isInvalidDate
, but I can go with the positive isValidDate
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with isInvalidDate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, done and rebased.
53e3aef
to
006fdfc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great 👍 Thanks for your patience.
…rnmobile/372-enter-key-detection-to-title * 'master' of https://github.com/WordPress/gutenberg: (29 commits) Update for RangeControl documentation (#12564) Plugin: Deprecate gutenberg_load_list_reusable_blocks (#13456) Update the columns attribute in onSelectImages so that if images are removed via the media modal, the columns can't be higher than the new number of images (#13488) Replace the fullscreen "exit" icon with a back arrow (#13403) Include :visited links in button color (#12183) Amazon Kindle block (#13510) Plugin: Deprecate gutenberg_prepare_blocks_for_js (#13457) Add watcher on Linux: change fs to node-watch (#13448) Plugin: Deprecate `gutenberg` theme support (#13458) Datepicker: Add inValidDay support (#12962) Block Switcher: Render disabled button even if multi-selection (#13431) Plugin: Deprecate gutenberg_register_post_types (#13468) Plugin: Deprecate register_tinymce_scripts (#13466) Set minimum of words for RSS excerpt (#13502) Plugin: Deprecate gutenberg_get_block_categories (#13454) Plugin: Deprecate gutenberg_content_block_version (#13469) API Fetch: Expose nonce on created middleware function (#13451) Plugin: Remove list screens integrations (#13459) Plugin: Remove core-defined block detection functions (#13467) Spec Parser: Move generated spec parser to package (#13493) ...
Description
Add the concept of unselectable days to the DatePicker's calendar by exposing
react-dates
propisOutsideRange
. Here is an example with Mondays made as invalid selections:What about invalidating dates via the inputs?
The changes here affect only the calendar (
<DatePicker />
component) and not the inputs (<TimePicker />
). Ideally, the same validation is passed along to the inputs to prevent selection of invalid days via the keyboard. That will take some design work to surface why an invalidation has occurred. I propose to handle that separately.Testing instructions
Since the concept of invalid days has no meaning for the text editor, changing code temporarily is the only way to evaluate this change.
to the implementation of
<DatePicker />
,gutenberg/packages/components/src/date-time/index.js
Lines 48 to 51 in 0c734e1
/wp-admin/post-new.php#/
.Types of changes
New feature: Expose a prop,
isInvalidDay
, to<DatePicker />
.Checklist: