Skip to content
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

DateTimePicker - hours dropdown not re-rendered when state changed programmatically #757

Closed
rendersbymarsh opened this issue Dec 3, 2020 · 2 comments
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Milestone

Comments

@rendersbymarsh
Copy link

Category

[ ] Enhancement

[x] Bug

[ ] Question

Version

Please specify what version of the library you are using: [ 2.2.0 ]

Expected / Desired Behavior / Question

I have a DateTimePicker on a form that's showing time displayed as dropdowns. If I programmatically change the value of the component, the date portion re-renders successfully but not the hours portion. (Changes made via UI work normally as they fire the onChange handler.)

My specific use case is an Undo button on the form that reverts the form values back to what was initially retrieved from the server.

Initial value:

image

After change via UI:

image

After Undo button pressed:

image

I know the value is actually being changed correctly in code, because if I close the panel containing the form and re-open it the value is back to what I would expect it to be. Therefore I think it's a bug with the component and how it detects a change to the hours portion of the time value.

Observed Behavior

The time portion should change to reflect the current value in state, both hours and minutes.

Steps to Reproduce

Code to recreate issue:

interface Entity {
  dateTimeField: Date;
}

const defaultEntityState = {
  dateTimeField: new Date('October 17, 2020 13:12:00')
};

const ChildComponent: React.FC = () => {
  const [entity, setEntity] = React.useState<Entity>(defaultEntityState);
  
  const onFieldChange = (name: string) => (value: any) => {
    setEntity({
      ...entity, [name]: value
    });
  }
  
  const revertTimeToDefault = (_e) => {
    setEntity(defaultEntityState);
  }
  
  const fieldValue = entity && entity.dateTimeField;
  
  return (
    <>
      <button onClick={revertTimeToDefault} type="button">Revert DateTime</button>
      <DateTimePicker
        firstDayOfWeek={DayOfWeek.Monday}
        strings={DayPickerStrings}
        placeholder="Select a date..."
        showLabels
        dateConvention={DateConvention.DateTime}
        timeConvention={TimeConvention.Hours24}
        timeDisplayControlType={TimeDisplayControlType.Dropdown}
        onChange={onFieldChange('dateTimeField')}
        value={fieldValue instanceof Date ? fieldValue : null}
        />  
    </>
  );
}

DayPickerStrings is just the set of labels:

const DayPickerStrings: IDateTimePickerStrings = {
    dateLabel: 'Date',
    timeLabel: 'Time',
    timeSeparator: ':',
    amDesignator: 'AM',
    pmDesignator: 'PM',
    months: [
        'January',
        'February',
        'March',
        'April',
        'May',
        'June',
        'July',
        'August',
        'September',
        'October',
        'November',
        'December',
    ],
    shortMonths: [
        'Jan',
        'Feb',
        'Mar',
        'Apr',
        'May',
        'Jun',
        'Jul',
        'Aug',
        'Sep',
        'Oct',
        'Nov',
        'Dec',
    ],
    days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    shortDays: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
    goToToday: 'Go to today',
    prevMonthAriaLabel: 'Go to previous month',
    nextMonthAriaLabel: 'Go to next month',
    prevYearAriaLabel: 'Go to previous year',
    nextYearAriaLabel: 'Go to next year',
};
@ghost
Copy link

ghost commented Dec 3, 2020

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 label Dec 3, 2020
@AJIXuMuK
Copy link
Collaborator

Thank you @BreakfastMaintenance for reporting this!

The fix has been done and will be included in the next release.

In a meanwhile you can test it in the beta version

@AJIXuMuK AJIXuMuK added status:fixed-next-drop Issue will be fixed in upcoming release. type:bug and removed Needs: Triage 🔍 labels Dec 13, 2020
@AJIXuMuK AJIXuMuK added this to the 2.3.0 milestone Dec 13, 2020
AJIXuMuK added a commit that referenced this issue Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:bug
Projects
None yet
Development

No branches or pull requests

2 participants