From 56884c45a276d804ff0aba9eb7e2c7fc417cf1bb Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Fri, 7 Oct 2022 11:55:59 +0200 Subject: [PATCH] [NO JIRA] Make date picker dropdown dismissable on Esc --- .../main/js/components/controls/DateInput.tsx | 129 ++-- .../__snapshots__/DateInput-test.tsx.snap | 638 +++++++++--------- 2 files changed, 393 insertions(+), 374 deletions(-) diff --git a/server/sonar-web/src/main/js/components/controls/DateInput.tsx b/server/sonar-web/src/main/js/components/controls/DateInput.tsx index 166d7717aee..67168910d28 100644 --- a/server/sonar-web/src/main/js/components/controls/DateInput.tsx +++ b/server/sonar-web/src/main/js/components/controls/DateInput.tsx @@ -35,6 +35,7 @@ import { translate } from '../../helpers/l10n'; import './DayPicker.css'; +import EscKeydownHandler from './EscKeydownHandler'; import Select from './Select'; import './styles.css'; @@ -163,71 +164,73 @@ export default class DateInput extends React.PureComponent { return ( - - (this.input = node)} - name={name} - onFocus={this.openCalendar} - placeholder={placeholder} - readOnly={true} - type="text" - value={value} - /> - - {value !== undefined && ( - + + (this.input = node)} + name={name} + onFocus={this.openCalendar} + placeholder={placeholder} + readOnly={true} + type="text" + value={value} /> - )} - {open && ( -
- - } - disabledDays={{ after, before: minDate }} - firstDayOfWeek={1} - modifiers={modifiers} - month={currentMonth} - navbarElement={} - onDayClick={this.handleDayClick} - onDayMouseEnter={this.handleDayMouseEnter} - selectedDays={selectedDays} - weekdaysLong={weekdaysLong} - weekdaysShort={weekdaysShort} + + {value !== undefined && ( + -
- )} -
+ )} + {open && ( +
+ + } + disabledDays={{ after, before: minDate }} + firstDayOfWeek={1} + modifiers={modifiers} + month={currentMonth} + navbarElement={} + onDayClick={this.handleDayClick} + onDayMouseEnter={this.handleDayMouseEnter} + selectedDays={selectedDays} + weekdaysLong={weekdaysLong} + weekdaysShort={weekdaysShort} + /> +
+ )} +
+
); } diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/DateInput-test.tsx.snap b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/DateInput-test.tsx.snap index fab0f857c18..6a3e0e6fb19 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/DateInput-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/DateInput-test.tsx.snap @@ -4,22 +4,26 @@ exports[`should render 1`] = ` - - - - + + + + + `; @@ -27,33 +31,37 @@ exports[`should render 2`] = ` - - - - + + + - + onClick={[Function]} + /> + + `; @@ -61,285 +69,289 @@ exports[`should render 3`] = ` - - - - -
- + } + classNames={ + Object { + "body": "DayPicker-Body", + "caption": "DayPicker-Caption", + "container": "DayPicker", + "day": "DayPicker-Day", + "disabled": "disabled", + "footer": "DayPicker-Footer", + "interactionDisabled": "DayPicker--interactionDisabled", + "month": "DayPicker-Month", + "months": "DayPicker-Months", + "navBar": "DayPicker-NavBar", + "navButtonInteractionDisabled": "DayPicker-NavButton--interactionDisabled", + "navButtonNext": "DayPicker-NavButton DayPicker-NavButton--next", + "navButtonPrev": "DayPicker-NavButton DayPicker-NavButton--prev", + "outside": "outside", + "selected": "selected", + "today": "today", + "todayButton": "DayPicker-TodayButton", + "week": "DayPicker-Week", + "weekNumber": "DayPicker-WeekNumber", + "weekday": "DayPicker-Weekday", + "weekdays": "DayPicker-Weekdays", + "weekdaysRow": "DayPicker-WeekdaysRow", + "wrapper": "DayPicker-wrapper", } - /> -
- - - - - } - classNames={ - Object { - "body": "DayPicker-Body", - "caption": "DayPicker-Caption", - "container": "DayPicker", - "day": "DayPicker-Day", - "disabled": "disabled", - "footer": "DayPicker-Footer", - "interactionDisabled": "DayPicker--interactionDisabled", - "month": "DayPicker-Month", - "months": "DayPicker-Months", - "navBar": "DayPicker-NavBar", - "navButtonInteractionDisabled": "DayPicker-NavButton--interactionDisabled", - "navButtonNext": "DayPicker-NavButton DayPicker-NavButton--next", - "navButtonPrev": "DayPicker-NavButton DayPicker-NavButton--prev", - "outside": "outside", - "selected": "selected", - "today": "today", - "todayButton": "DayPicker-TodayButton", - "week": "DayPicker-Week", - "weekNumber": "DayPicker-WeekNumber", - "weekday": "DayPicker-Weekday", - "weekdays": "DayPicker-Weekdays", - "weekdaysRow": "DayPicker-WeekdaysRow", - "wrapper": "DayPicker-wrapper", } - } - disabledDays={ - Object { - "after": 2018-02-05T00:00:00.000Z, - "before": 2018-01-17T00:00:00.000Z, + disabledDays={ + Object { + "after": 2018-02-05T00:00:00.000Z, + "before": 2018-01-17T00:00:00.000Z, + } } - } - enableOutsideDaysClick={true} - firstDayOfWeek={1} - fixedWeeks={false} - labels={ - Object { - "nextMonth": "Next Month", - "previousMonth": "Previous Month", + enableOutsideDaysClick={true} + firstDayOfWeek={1} + fixedWeeks={false} + labels={ + Object { + "nextMonth": "Next Month", + "previousMonth": "Previous Month", + } } - } - locale="en" - localeUtils={ - Object { - "default": Object { + locale="en" + localeUtils={ + Object { + "default": Object { + "formatDay": [Function], + "formatMonthTitle": [Function], + "formatWeekdayLong": [Function], + "formatWeekdayShort": [Function], + "getFirstDayOfWeek": [Function], + "getMonths": [Function], + }, "formatDay": [Function], "formatMonthTitle": [Function], "formatWeekdayLong": [Function], "formatWeekdayShort": [Function], "getFirstDayOfWeek": [Function], "getMonths": [Function], - }, - "formatDay": [Function], - "formatMonthTitle": [Function], - "formatWeekdayLong": [Function], - "formatWeekdayShort": [Function], - "getFirstDayOfWeek": [Function], - "getMonths": [Function], + } } - } - month={2018-01-17T00:00:00.000Z} - navbarElement={} - numberOfMonths={1} - onDayClick={[Function]} - onDayMouseEnter={[Function]} - pagedNavigation={false} - renderDay={[Function]} - renderWeek={[Function]} - reverseMonths={false} - selectedDays={ - Array [ - 2018-01-17T00:00:00.000Z, - ] - } - showOutsideDays={false} - showWeekDays={true} - showWeekNumbers={false} - tabIndex={0} - weekdayElement={} - weekdaysLong={ - Array [ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - ] - } - weekdaysShort={ - Array [ - "Sun", - "Mon", - "Tue", - "Wed", - "Thu", - "Fri", - "Sat", - ] - } - /> - -
+ month={2018-01-17T00:00:00.000Z} + navbarElement={} + numberOfMonths={1} + onDayClick={[Function]} + onDayMouseEnter={[Function]} + pagedNavigation={false} + renderDay={[Function]} + renderWeek={[Function]} + reverseMonths={false} + selectedDays={ + Array [ + 2018-01-17T00:00:00.000Z, + ] + } + showOutsideDays={false} + showWeekDays={true} + showWeekNumbers={false} + tabIndex={0} + weekdayElement={} + weekdaysLong={ + Array [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ] + } + weekdaysShort={ + Array [ + "Sun", + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + "Sat", + ] + } + /> + + +
`; @@ -347,21 +359,25 @@ exports[`should select a day 1`] = ` - - - - + + + + + `; -- 2.39.5