Skip to content

Commit

Permalink
Improve input mask UX and a11y (#1661)
Browse files Browse the repository at this point in the history
* Add jest debug configuration

* Move jest config to separate file

* Change input mask generation logic

* Use new geFormatHelperText date-io method to generate helper text and placeholder

* Update @date-io/jalaali and @date-io/hijiri

* [docs] Update component demo titles

* Fix mask input  issues and update e2e tests

* Optimize new masked input for date range picker

* Remove meaningless comment

* Update component based tests

* Use auto injecting dependencies for hooks

* Remove maskChar prop

* Again remove `date` from the useEffect dependency in usePickerState

* Make keyboard input isFocused mutable ref instead of state
  • Loading branch information
dmtrKovalenko authored Apr 21, 2020
1 parent 1c011a4 commit b223777
Show file tree
Hide file tree
Showing 22 changed files with 427 additions and 358 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/lib/node_modules/.bin/jest",
"args": ["--config", "${workspaceFolder}/lib/jest.config.js", "${fileBasenameNoExtension}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/lib/node_modules/jest/bin/jest"
}
},
{
"type": "chrome",
"request": "launch",
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"dependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
"@date-io/hijri": "^2.2.0",
"@date-io/jalaali": "^2.0.0",
"@date-io/hijri": "^2.6.0",
"@date-io/jalaali": "^2.6.0",
"@mapbox/rehype-prism": "^0.4.0",
"@material-ui/core": "^4.9.9",
"@material-ui/icons": "^4.9.1",
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/demo/datepicker/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as StaticDatePicker from './StaticDatePicker.example';
import * as DatePickers from './DatePickers.example';
import * as AdvancedKeyboard from './AdvancedKeyboard.example';

<PageMeta component="Datepicker" />
<PageMeta component="DatePicker" />

## Date picker

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/demo/daterangepicker/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as MinMaxDateRangePicker from './MinMaxDateRangePicker.example';
import * as CalendarsDateRangePicker from './CalendarsDateRangePicker.example';
import * as StaticDateRangePicker from './StaticDateRangePicker.example';

<PageMeta component="Datepicker" />
<PageMeta component="DateRangePicker" />

## Date picker

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/demo/datetime-picker/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as DateTimePickers from './DateTimePickers.example';
import * as CustomDateTimePicker from './CustomDateTimePicker.example';
import * as DateTimeValidation from './DateTimeValidation.example';

<PageMeta component="Date & Time picker" />
<PageMeta component="DateTimePicker" />

## Date & Time picker

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/demo/timepicker/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as InlineTimePicker from './InlineTimePicker.example';
import * as StaticTimePicker from './StaticTimePicker.example';
import * as SecondsTimePicker from './SecondsTimePicker.example';

<PageMeta component="Timepicker" />
<PageMeta component="TimePicker" />

## Time Picker

Expand Down
57 changes: 16 additions & 41 deletions docs/pages/localization/Date-fns.example.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as React from 'react';
import frLocale from 'date-fns/locale/fr';
import ruLocale from 'date-fns/locale/ru';
import enLocale from 'date-fns/locale/en-US';
import MoreIcon from '@material-ui/icons/MoreVert';
import React, { useState, useCallback } from 'react';
import DateFnsAdapter from '@material-ui/pickers/adapter/date-fns';
import { IconButton, Menu, MenuItem } from '@material-ui/core';
import { Button, ButtonGroup } from '@material-ui/core';
import { DatePicker, LocalizationProvider } from '@material-ui/pickers';

const localeMap = {
Expand All @@ -13,55 +12,31 @@ const localeMap = {
ru: ruLocale,
};

function DateFnsLocalizationExample() {
const [locale, setLocale] = useState('ru');
const [anchorEl, setAnchorEl] = useState(null);
const [selectedDate, handleDateChange] = useState(new Date());
const maskMap = {
fr: '__/__/____',
en: '__/__/____',
ru: '__.__.____',
};

const handleMenuOpen = useCallback(e => {
e.stopPropagation();
setAnchorEl(e.currentTarget);
}, []);
function DateFnsLocalizationExample() {
const [locale, setLocale] = React.useState('ru');
const [selectedDate, handleDateChange] = React.useState(new Date());

const selectLocale = useCallback(locale => {
const selectLocale = React.useCallback(locale => {
setLocale(locale);
setAnchorEl(null);
}, []);

return (
<LocalizationProvider dateAdapter={DateFnsAdapter} locale={localeMap[locale]}>
<DatePicker
value={selectedDate}
onChange={handleDateChange}
InputProps={{
endAdornment: (
<IconButton
aria-label="Select locale"
onClick={handleMenuOpen}
aria-owns={anchorEl ? 'locale-menu' : undefined}
>
<MoreIcon />
</IconButton>
),
}}
/>
<DatePicker mask={maskMap[locale]} value={selectedDate} onChange={handleDateChange} />

<Menu
id="locale-menu"
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={() => setAnchorEl(null)}
>
<ButtonGroup>
{Object.keys(localeMap).map(localeItem => (
<MenuItem
key={localeItem}
selected={localeItem === locale}
onClick={() => selectLocale(localeItem)}
>
<Button key={localeItem} onClick={() => selectLocale(localeItem)}>
{localeItem}
</MenuItem>
</Button>
))}
</Menu>
</ButtonGroup>
</LocalizationProvider>
);
}
Expand Down
45 changes: 12 additions & 33 deletions docs/pages/localization/Moment.example.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import moment from 'moment';
import MoreIcon from '@material-ui/icons/MoreVert';
import React, { useState, useCallback } from 'react';
import MomentAdapter from '@material-ui/pickers/adapter/moment';
import { IconButton, Menu, MenuItem } from '@material-ui/core';
import { Button, ButtonGroup } from '@material-ui/core';
import { DatePicker, LocalizationProvider } from '@material-ui/pickers';
import 'moment/locale/fr';
import 'moment/locale/ru';
Expand All @@ -15,57 +14,37 @@ const localeMap = {
ru: 'ru',
};

const maskMap = {
fr: '__/__/____',
en: '__/__/____',
ru: '__.__.____',
};

function MomentLocalizationExample() {
const [locale, setLocale] = useState('fr');
const [anchorEl, setAnchorEl] = useState(null);
const [selectedDate, handleDateChange] = useState(new Date());

const handleMenuOpen = useCallback(e => {
e.stopPropagation();
setAnchorEl(e.currentTarget);
}, []);

const selectLocale = useCallback(locale => {
moment.locale(locale);

setLocale(locale);
setAnchorEl(null);
}, []);

return (
<LocalizationProvider dateLibInstance={moment} dateAdapter={MomentAdapter} locale={locale}>
<DatePicker
mask={maskMap[locale]}
value={selectedDate}
onChange={date => handleDateChange(date)}
InputProps={{
endAdornment: (
<IconButton
aria-label="Select locale"
onClick={handleMenuOpen}
aria-owns={anchorEl ? 'locale-menu' : undefined}
>
<MoreIcon />
</IconButton>
),
}}
/>

<Menu
id="locale-menu"
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={() => setAnchorEl(null)}
>
<ButtonGroup>
{Object.keys(localeMap).map(localeItem => (
<MenuItem
key={localeItem}
selected={localeItem === locale}
onClick={() => selectLocale(localeItem)}
>
<Button key={localeItem} onClick={() => selectLocale(localeItem)}>
{localeItem}
</MenuItem>
</Button>
))}
</Menu>
</ButtonGroup>
</LocalizationProvider>
);
}
Expand Down
68 changes: 4 additions & 64 deletions docs/prop-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit b223777

@vercel
Copy link

@vercel vercel bot commented on b223777 Apr 21, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.