-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-datepicker-compat): Add error handling to DatePicker and update popup's padding #27637
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
Merged
sopranopillow
merged 9 commits into
microsoft:master
from
sopranopillow:react-datepicker-compat/error-handling
Apr 20, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be7fccc
Adding error handling and an example of how to use it
sopranopillow 262abc5
Merge branch 'master' of https://www.github.com/microsoft/fluentui in…
sopranopillow 9a88167
change files
sopranopillow 04e983f
reordering values
sopranopillow 3bcdc9a
updating api
sopranopillow f3bb8a2
syncpack
sopranopillow 9887545
docs
sopranopillow 4828faf
remove padding
sopranopillow cc9f4f2
requested changes
sopranopillow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-datepicker-compat-59a888f8-093f-449c-b49e-4f580894da5e.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "feat: Add error handling to DatePicker.", | ||
| "packageName": "@fluentui/react-datepicker-compat", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
packages/react-components/react-datepicker-compat/src/components/DatePicker/defaults.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,18 @@ | ||
| import { defaultCalendarStrings } from '../Calendar/defaults'; | ||
| import type { DatePickerStrings } from './DatePicker.types'; | ||
| import type { CalendarStrings } from '../../utils/index'; | ||
| import type { DatePickerErrorData } from './DatePicker.types'; | ||
|
|
||
| // TODO: Once we have error handling hook, this needs to be either renamed or removed. | ||
| export const defaultDatePickerStrings: DatePickerStrings = { | ||
| export const defaultDatePickerStrings: CalendarStrings = { | ||
| ...defaultCalendarStrings, | ||
| prevMonthAriaLabel: 'Go to previous month', | ||
| nextMonthAriaLabel: 'Go to next month', | ||
| prevYearAriaLabel: 'Go to previous year', | ||
| nextYearAriaLabel: 'Go to next year', | ||
| closeButtonAriaLabel: 'Close date picker', | ||
| isRequiredErrorMessage: 'Field is required', | ||
| invalidInputErrorMessage: 'Invalid date format', | ||
| isResetStatusMessage: 'Invalid entry "{0}", date reset to "{1}"', | ||
| }; | ||
|
|
||
| export const defaultDatePickerErrorStrings: Record<DatePickerErrorData['error'], string> = { | ||
| 'invalid-input': 'Invalid date format', | ||
| 'out-of-bounds': 'Date is out of bounds', | ||
| 'required-input': 'Field is required', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...components/react-datepicker-compat/stories/DatePicker/DatePickerErrorHandling.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import * as React from 'react'; | ||
| import { addMonths, addYears, DatePicker, defaultDatePickerErrorStrings } from '@fluentui/react-datepicker-compat'; | ||
| import { Field, makeStyles } from '@fluentui/react-components'; | ||
| import type { DatePickerErrorData } from '../../src/DatePicker'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| control: { | ||
| maxWidth: '300px', | ||
| }, | ||
| }); | ||
|
|
||
| const today = new Date(Date.now()); | ||
| const minDate = addMonths(today, -1); | ||
| const maxDate = addYears(today, 1); | ||
|
|
||
| export const ErrorHandling = () => { | ||
| const styles = useStyles(); | ||
| const [error, setError] = React.useState<DatePickerErrorData['error'] | undefined>(undefined); | ||
|
|
||
| return ( | ||
| <Field | ||
| required | ||
| label={ | ||
| `Select a date out of bounds (minDate: ${minDate}, maxDate: ${maxDate}),` + | ||
| ` type an invalid input, or leave the input empty and close the DatePicker.` | ||
| } | ||
| validationMessage={error && defaultDatePickerErrorStrings[error]} | ||
| > | ||
| <DatePicker | ||
| minDate={minDate} | ||
| maxDate={maxDate} | ||
| placeholder="Select a date..." | ||
| allowTextInput | ||
| onValidationError={data => setError(data.error)} | ||
| className={styles.control} | ||
| /> | ||
| </Field> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.