From 1d4b562350489014a1427158b0a680b38336fc68 Mon Sep 17 00:00:00 2001 From: ashishkcerner <126875089+ashishkcerner@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:40:04 +0530 Subject: [PATCH] [date-time-picker] Defect fixes (#2036) --- .github/workflows/ci-cd.yml | 2 +- packages/terra-date-picker/CHANGELOG.md | 4 +++ packages/terra-date-picker/src/DateInput.jsx | 3 ++ .../src/react-datepicker/calendar.jsx | 11 +++--- .../src/react-datepicker/date_utils.js | 17 +++++++++ .../src/react-datepicker/index.jsx | 8 +++-- .../__snapshots__/DateInput.test.jsx.snap | 36 +++++++++++++++++++ .../__snapshots__/DatePicker.test.jsx.snap | 9 +++++ .../DatePickerField.test.jsx.snap | 27 ++++++++++++++ packages/terra-framework-docs/CHANGELOG.md | 3 ++ .../example/DateTimePickerTimeZone.jsx | 29 +++++++-------- 11 files changed, 127 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 92a063f38f0..a789b90930f 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -116,4 +116,4 @@ jobs: keep_files: true user_name: 'github-actions[bot]' user_email: 'github-actions[bot]@users.noreply.github.com' - commit_message: 'chore(docs): Regenerate docs' + commit_message: 'chore(docs): Regenerate docs' \ No newline at end of file diff --git a/packages/terra-date-picker/CHANGELOG.md b/packages/terra-date-picker/CHANGELOG.md index 494307e2f62..117c7699677 100644 --- a/packages/terra-date-picker/CHANGELOG.md +++ b/packages/terra-date-picker/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* Changed + * Fixed the invalid case for SR announcement. + * Changed the SR announcement for changing date from calender. + ## 4.98.1 - (February 16, 2024) * Fixed diff --git a/packages/terra-date-picker/src/DateInput.jsx b/packages/terra-date-picker/src/DateInput.jsx index 096b2489861..87be840c8e0 100644 --- a/packages/terra-date-picker/src/DateInput.jsx +++ b/packages/terra-date-picker/src/DateInput.jsx @@ -714,6 +714,7 @@ const DatePickerInput = (props) => { maxLength="2" size="2" pattern="\d*" + aria-invalid={isInvalid} aria-required={required} aria-label={`${ariaLabel ? `${ariaLabel} ${intl.formatMessage({ id: 'Terra.datePicker.dayLabel' })}` : intl.formatMessage({ id: 'Terra.datePicker.dayLabel' })}`} aria-describedby={ariaDescriptionIds} @@ -745,6 +746,7 @@ const DatePickerInput = (props) => { maxLength="2" size="2" pattern="\d*" + aria-invalid={isInvalid} aria-required={required} aria-label={`${ariaLabel ? `${ariaLabel} ${intl.formatMessage({ id: 'Terra.datePicker.monthLabel' })}` : intl.formatMessage({ id: 'Terra.datePicker.monthLabel' })}`} aria-describedby={ariaDescriptionIds} @@ -776,6 +778,7 @@ const DatePickerInput = (props) => { maxLength="4" size="4" pattern="\d*" + aria-invalid={isInvalid} aria-required={required} aria-label={`${ariaLabel ? `${ariaLabel} ${intl.formatMessage({ id: 'Terra.datePicker.yearLabel' })}` : intl.formatMessage({ id: 'Terra.datePicker.yearLabel' })}`} aria-describedby={ariaDescriptionIds} diff --git a/packages/terra-date-picker/src/react-datepicker/calendar.jsx b/packages/terra-date-picker/src/react-datepicker/calendar.jsx index ec0797b3581..6f562bcea62 100644 --- a/packages/terra-date-picker/src/react-datepicker/calendar.jsx +++ b/packages/terra-date-picker/src/react-datepicker/calendar.jsx @@ -32,7 +32,8 @@ import { allDaysDisabledAfter, getEffectiveMinDate, getEffectiveMaxDate, - isDayDisabled + isDayDisabled, + dateValues } from './date_utils' const cx = classNames.bind(styles); @@ -413,7 +414,7 @@ export default class Calendar extends React.Component { isMonthChanged: true, date: getStartOfMonth(addMonths(cloneDate(this.state.date), 1)), }, () => this.handleMonthChange(this.state.date)) - this.props.setPreSelection(getStartOfMonth(addMonths(cloneDate(this.state.date), 1))); + this.props.setPreSelection(getStartOfMonth(addMonths(cloneDate(this.state.date), 1)),dateValues.MONTH,addMonths(cloneDate(this.state.date), 1)); // To check if button is pressed using mouse or keyboard if(event.target.type === undefined) { this.setState({ calendarIsKeyboardFocused : false}); @@ -426,7 +427,7 @@ export default class Calendar extends React.Component { isMonthChanged: true, date: getStartOfMonth(subtractMonths(cloneDate(this.state.date), 1)) }, () => this.handleMonthChange(this.state.date)) - this.props.setPreSelection(getStartOfMonth(subtractMonths(cloneDate(this.state.date), 1))); + this.props.setPreSelection(getStartOfMonth(subtractMonths(cloneDate(this.state.date), 1)),dateValues.MONTH,subtractMonths(cloneDate(this.state.date), 1)); // To check if button is pressed using mouse or keyboard if(event.target.type === undefined) { this.setState({ calendarIsKeyboardFocused : false}); @@ -464,7 +465,7 @@ export default class Calendar extends React.Component { isMonthChanged: true, date: getStartOfMonth(setYear(cloneDate(this.state.date), year)) }) - this.props.setPreSelection(getStartOfMonth(setYear(cloneDate(this.state.date), year))); + this.props.setPreSelection(getStartOfMonth(setYear(cloneDate(this.state.date), year)),dateValues.YEAR,year); } changeMonth = (month) => { @@ -472,7 +473,7 @@ export default class Calendar extends React.Component { isMonthChanged: true, date: getStartOfMonth(setMonth(cloneDate(this.state.date), month)) }, () => this.handleMonthChange(this.state.date)) - this.props.setPreSelection(getStartOfMonth(setMonth(cloneDate(this.state.date), month))); + this.props.setPreSelection(getStartOfMonth(setMonth(cloneDate(this.state.date), month)),dateValues.MONTH,month); } header = (date = this.state.date) => { diff --git a/packages/terra-date-picker/src/react-datepicker/date_utils.js b/packages/terra-date-picker/src/react-datepicker/date_utils.js index aacdc838e35..ad1c25990d7 100644 --- a/packages/terra-date-picker/src/react-datepicker/date_utils.js +++ b/packages/terra-date-picker/src/react-datepicker/date_utils.js @@ -376,3 +376,20 @@ export function getLocalizedDateForScreenReader (date, props) { return localizedDateLabel; } + +export function getMonthFromDate(date, props) { + const { intl, locale } = props; + let month = ''; + + if (date && date.isValid()) { + const localizedDate = localizeDate(date, locale); + month = localizedDate.format('MMMM'); + } + + return month; +} + +export const dateValues = { + MONTH: 'month', + YEAR: 'year', +}; diff --git a/packages/terra-date-picker/src/react-datepicker/index.jsx b/packages/terra-date-picker/src/react-datepicker/index.jsx index 10499ef395a..2cd48d7a2b6 100644 --- a/packages/terra-date-picker/src/react-datepicker/index.jsx +++ b/packages/terra-date-picker/src/react-datepicker/index.jsx @@ -34,7 +34,9 @@ import { parseDate, safeDateFormat, getHightLightDaysMap, - getLocalizedDateForScreenReader + getLocalizedDateForScreenReader, + getMonthFromDate, + dateValues } from './date_utils' import onClickOutside from 'react-onclickoutside' import styles from './stylesheets/react_datepicker.module.scss' @@ -582,12 +584,14 @@ class DatePicker extends React.Component { } } - setPreSelection = (date) => { + setPreSelection = (date,type,value) => { const isValidDateSelection = date ? isDayInRange(date, this.props.minDate, this.props.maxDate) : true if (isValidDateSelection) { this.setState({ preSelection: date }) + type === dateValues.MONTH ? this.updateAriaLiveStatus(getMonthFromDate(date, this.props)) : + type === dateValues.YEAR ? this.updateAriaLiveStatus(value) : this.updateAriaLiveStatus(getLocalizedDateForScreenReader(date, this.props)); } } diff --git a/packages/terra-date-picker/tests/jest/__snapshots__/DateInput.test.jsx.snap b/packages/terra-date-picker/tests/jest/__snapshots__/DateInput.test.jsx.snap index 04860776e58..d28e3bf16a0 100644 --- a/packages/terra-date-picker/tests/jest/__snapshots__/DateInput.test.jsx.snap +++ b/packages/terra-date-picker/tests/jest/__snapshots__/DateInput.test.jsx.snap @@ -111,6 +111,7 @@ exports[`correctly applies the theme context className 1`] = ` day={ -
- Initial Timezone: - {timeZone} -
-