-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[Bug]: Specifying defaultValue doesn't modify the timePicker #25730
Comments
@madhurauti please provide a code repro, issues without code repro will have less priority |
The default value is not even working on the official website: https://developer.microsoft.com/en-us/fluentui#/controls/web/timepicker |
@ling1726 - I am not able to get the same behavior in sandbox. Hence, I cannot provide the sandbox link. In the examples shown here - https://developer.microsoft.com/en-us/fluentui#/controls/web/timepicker - all the timepicker controls start out empty. When timepicker is loaded with default value (for the first time it rounds to the next 30 minute interval - so if you pass 1:37 -> timepicker will have 2:00) and without default value (it rounds to the next 30 minute interval w.r.t current time). I believe this issue - #21824 also alludes to the problem I am facing. if the timepicker cannot start with empty value then at least I want timepicker to take the default value and w.r.t that value render the next 30 minute interval, however, it seems this only happens when I load the timepicker for the first time. Problem scenario (assume current time is 1:37 PM):
|
Same behavior, repro link: https://codepen.io/ElvenProgrammer/pen/oNMGErB?editors=1111 |
the problem is that the userText is set to '' (an empty string) on initialization of the component. this is passed to combobox text prop and because of that the selection is cleared. |
Indeed, in my project I recreated the wrapper around the combobox and fixed it, but for sure it would be nice to have it supported natively (and v9 still doesn't support date nor time pickers) |
I ran into this issue today. It seems this PR (#24665) allowing comboBox to include an empty string has caused it. Starting from 8.99.0 - so for anybody stuck with this, a downgrade to 8.98.8 solved it for the moment. |
@elvenprogrammer could you add a little example on how have you managed to wrap the component to have it display a default time value? I'd be ideal if you could update your sandbox, but a little guidance on what props to modify would already be fantastic :) |
Nothing fancy, I just copied and pasted the source code and slightly modified it:
|
…ates (#26482) * Update prop names, make renamed currentDate prop controlled * Added DatePicker and TimePicker combination example * Rephrase example text * Combine ComboBox imports * Fixed ComboBox import and updated DateTimePicker example * Moved examples into standalone files * Refactors and use new dateAnchor prop * Updated all examples * This should resolve the rest * This should resolve the outstanding issues... * Updated example strings * Updated examples * More changes to the basic example * Removed useComboBoxAsMenuWidth prop * Update formatTimeString function to return 00 if hours is 24 * Addressed comments * Renamed baseDate parameter to dateStartAnchor * Added prop onGetErrorMessage to get validation result * Set selectedTime to invalid or undefined * Clamp value to updated dateAnchor * Make docs look nice and readable * Removed unneeded imports * Updated clampedStartAnchor initialization value * Use internalDateAnchor * Use fallbackDateAnchor and update DateTimePicker example * Revert to ITimePickerProps to extend original omitted IComboBoxProps * Addressed comments * API snapshot update * Updated TimePicker tests and added test for new controlled component variant * Added test for handling changed base date anchor * Verify selected time changes on dateAnchor change * Added yarn change files * Resolve linting errors * Resolved more linting errors * Resolved linting import error by in-lining stack and styles * Addressed comments * Revert onChange prop types to avoid breaking changes and pass React.FormEvent<IComboBox> to setSelectedTime callback * Added explicit undefined pass to setSelectedTime in cases the dateAnchor changes * Updated examples and call onChange outside of useControllableValue to pass in proper event type * Control snapping of TimePicker values on DatePicker anchor change * Added tests for using defaultValue or value as date anchors * Took snapping logic out, fixed invalid key bug, and shared getDateAnchor function * Pass in placeholder since placeholder prop no longer has default value * Reflect optional timeOutOfBoundsErrorMessage string * Updated tests and snapshot * Addressed comments * Removed unnecessary string state variables * Followed comment suggestion and replaced onGetErrorMessage with onValidationError prop * Added onValidationError example * Added onValidationError test case * Export TimePickerErrorData * Renamed onValidationError and TimePickerErrorData to onValidationResult and TimePickerValidationData * Renamed example to reflect new callback prop * Use new example and fix casing * Use onValidationResult and only call when stored error message differs from latest error message * Added test for verifying onValidateResult only gets called on error message changes * Split big test into two smaller tests
* master: applying package updates microsoft#25730: TimePicker Default Value Fix, Controllable Usage, Example Updates (microsoft#26482) docs(react-datepicker-compat): Add description to README.md (microsoft#27677) Updated to use single hook selector (microsoft#27491) fix: Make border around Avatar's badge transparent using a mask (microsoft#27527) Disable focus on non-interactive elements (microsoft#27580) feat(react-drawer): implement "prevent close on click outside" feature (microsoft#27551)
* master: applying package updates microsoft#25730: TimePicker Default Value Fix, Controllable Usage, Example Updates (microsoft#26482) docs(react-datepicker-compat): Add description to README.md (microsoft#27677) Updated to use single hook selector (microsoft#27491) fix: Make border around Avatar's badge transparent using a mask (microsoft#27527) Disable focus on non-interactive elements (microsoft#27580) feat(react-drawer): implement "prevent close on click outside" feature (microsoft#27551)
* feat/drawer-components: (81 commits) docs: remove TODO marks fix: remove conflict code leftover applying package updates microsoft#25730: TimePicker Default Value Fix, Controllable Usage, Example Updates (microsoft#26482) docs(react-datepicker-compat): Add description to README.md (microsoft#27677) Updated to use single hook selector (microsoft#27491) fix: Make border around Avatar's badge transparent using a mask (microsoft#27527) Disable focus on non-interactive elements (microsoft#27580) feat(react-drawer): implement "prevent close on click outside" feature (microsoft#27551) fix(react-datepicker-compat): Make onValidationError onValidationResult so the error is updated when there's no longer an error (microsoft#27655) Fix `@fluentui/react-portal-compat`: to be compatible with React 18 (microsoft#27577) chore: fix versions of @fluentui/react-datepicker-compat (microsoft#27666) applying package updates applying package updates Make line chart screen reader accessible (microsoft#27632) fix(react-examples): Improve keyboard navigation in ContextualMenu.CustomMenuList (microsoft#25172) docs(react-textarea): Update examples to use Field (microsoft#27644) bugfix(react-dialog): `DialogTitle` root as `h2` by default (microsoft#27555) applying package updates chore: restructure stories, add separate category for flat tree (microsoft#27586) ...
I tested the new version, now I'm able to control the selected value, but stil I'm not able to reset it, e.g. setting it to undefined:
|
Library
React / v8 (@fluentui/react)
System Info
Are you reporting Accessibility issue?
no
Reproduction
https://codepen.io/pen/?template=jOVZXaW
Bug Description
Browser: Chrome
The 6:00 AM Timepicker is incorrect. Based on the timepicker logic it should be set to 12:30 since the default value is set to 00:18 (see screenshot)
Actual Behavior
Specifying defaultValue for the timepicker doesn't set the value correctly.
Expected Behavior
Specifying defaultValue should reflect the value correctly in the timepicker.
Logs
Requested priority
Blocking
Products/sites affected
No response
Are you willing to submit a PR to fix?
yes
Validations
The text was updated successfully, but these errors were encountered: