instructure / instructure-ui

A UI Component Library made by Instructure, Inc.
https://instructure.design/
Other
435 stars 98 forks source link

feat(ui-date-time-input): add initialTimeForNewDate prop to datetimei… #1414

Closed joyenjoyer closed 7 months ago

joyenjoyer commented 7 months ago

…nput

Closes: INSTUI-3966

Test:

  1. set initialTimeForNewDate on DateTimeInput
  2. make sure defaultValue prop is not set
  3. pick a date
  4. observe if the chosen initialTimeForNewDate value appears in the TimeSelect input field
github-actions[bot] commented 7 months ago

Preview URL: https://1414--preview-instui.netlify.app

joyenjoyer commented 7 months ago

looks better now, but if there is a defaultValue then its value is ignored. To reproduce use this code:

class Example extends React.Component {
  render () {
    return (
      <div style= { {height: '10rem',width: '40em'}}>
        <DateTimeInput
          description="Pick a date and time"
          datePlaceholder="Choose a date"
          dateRenderLabel="Date"
          timeRenderLabel="Time"
          invalidDateTimeMessage="Invalid date!"
          prevMonthLabel='Previous month'
          nextMonthLabel='Next month'
          defaultValue="2018-01-18T13:30"
          layout="columns"
          initialTimeForNewDate="23:43"
        />
    </div>)
  }
}
render(<Example />)

delete the date value, click outside of the component, and then enter a valid date. It will use 12:00 instead of 23:43 as date value

This is what we discussed in a meeting and what you requested in the comment above the last one:

if I enter both defaultValue and initialTimeForNewDate the component crashes with TypeError: Cannot read properties of undefined (reading 'timeSelectValue') it should disregard initialTimeForNewDate and output a warning that it does nothing

If both props are present now, initialTimeForNewDate is ignored. A warning message is thrown too:

Warning: [DateTimeInput] if defaultValue is set, initialTimeForNewDate will be ignored. logMessage @ console.js:53

Let me know if there is a misunderstanding!