Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "In Timepicker intialValue const used the useConst hook which does not update the initial value of the timepicker if the TimePicker receive updated date via props",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
6 changes: 3 additions & 3 deletions packages/react/src/components/TimePicker/TimePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { useConst } from '@fluentui/react-hooks';
import { KeyCodes } from '../../Utilities';
import {
TimeConstants,
Expand All @@ -8,6 +7,7 @@ import {
ceilMinuteToIncrement,
getDateFromTimeSelection,
} from '@fluentui/date-time-utilities';
import { useControllableValue } from '@fluentui/react-hooks';
import { ComboBox } from '../../ComboBox';
import type { IComboBox, IComboBoxOption } from '../../ComboBox';
import type { ITimePickerProps, ITimeRange, ITimePickerStrings } from './TimePicker.types';
Expand Down Expand Up @@ -52,8 +52,8 @@ export const TimePicker: React.FunctionComponent<ITimePickerProps> = ({

const optionsCount = getDropdownOptionsCount(increments, timeRange);

const initialValue = useConst(defaultValue || new Date());
const baseDate: Date = React.useMemo(() => generateBaseDate(increments, timeRange, initialValue), [
const [initialValue] = useControllableValue(defaultValue, new Date());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct change. The first argument to useControllableValue is meant to be the controlled value. defaultValue is React's way of handling uncontrolled values.

I think this change needs to update TimePicker to support both controlled and uncontrolled usage. However, I'm not 100% certain how that should be handled as I believe TimePicker is used more like a ComboBox so adding a controlled value may not make sense.

@CheerfulSatchel, do you have any ideas on how to proceed here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But defaultValue will be passed as props. If it is used with datepicker then default value will hold the value selected in datepicker.

I think in other controls also this scenario is handled in same way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spmonahan @CheerfulSatchel have we reached on any consensus for this issue?

const baseDate: Date = React.useMemo(() => generateBaseDate(increments, timeRange, initialValue as Date), [
increments,
timeRange,
initialValue,
Expand Down