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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] Include date/time in accessible name depending on picker variant #27420

Open
2 tasks done
DoctorDerek opened this issue Jul 24, 2021 · 0 comments
Open
2 tasks done
Labels
accessibility a11y component: pickers This is the name of the generic UI component, not the React module!

Comments

@DoctorDerek
Copy link

  • The issue is present in the latest release. "@material-ui/lab": "^5.0.0-alpha.30",
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

  1. <DateTimePicker> generates label aria-label="Choose date, selected date is Jul 23, 2021"
  2. <TimePicker> generates label aria-label="Choose date, selected date is Jul 23, 2021"

Expected Behavior 馃

  1. <DateTimePicker> would generate a label including date & time
  2. <TimePicker> would generate a label including just time, no date

Steps to Reproduce 馃暪

Steps:

  1. No reproduction is needed, as this behavior is clear in the source code.
  2. These three components should have different defaults, not the same defaults:

https://github.com/mui-org/material-ui/blob/9693e8ba8a8c9122c530f26d84645de35277e9a8/packages/material-ui-lab/src/DatePicker/DatePicker.tsx#L183-L187
https://github.com/mui-org/material-ui/blob/9693e8ba8a8c9122c530f26d84645de35277e9a8/packages/material-ui-lab/src/TimePicker/TimePicker.tsx#L172-L176
https://github.com/mui-org/material-ui/blob/9693e8ba8a8c9122c530f26d84645de35277e9a8/packages/material-ui-lab/src/DateTimePicker/DateTimePicker.tsx#L214-L218

Context 馃敠

Currently <DateTimePicker> and <TimePicker> are not accessible; they are only pretending to be so.

I was looking to query the aria-label for <DateTimePicker> by the word "time" but couldn't do so. I could only query the optional helperText I was using, which is not associated with the in the DOM flow.

Your Environment 馃寧

My environment is not applicable.

Proposed Solution

Either of these seem like adequate solutions to me as overrides:

JavaScript code with default Date toString:

        <LocalizationProvider dateAdapter={AdapterDateFns}>
          <DateTimePicker
            value={selectedDateTime}
            onChange={setSelectedDateTime}
            getOpenDialogAriaText={(value) =>
              `Choose date and time, selected date and time is ${value}`
            }
            renderInput={(props) => (
              <TextField {...props} helperText="selected time" />
            )}
          />
        </LocalizationProvider>

resulting in:
aria-label="Choose date and time, selected date and time is Fri Jul 23 2021 19:36:38 GMT-0500 (Eastern Standard Time)"

or

TypeScript code with import { format } from "date-fns"

        <LocalizationProvider dateAdapter={AdapterDateFns}>
          <DateTimePicker
            value={selectedDateTime}
            onChange={setSelectedDateTime}
            getOpenDialogAriaText={(value) =>
              `Choose date and time, selected date and time is ${
                value && format(value as Date, "MM/dd/yyyy hh:mm aaa")
              }`
            }
            renderInput={(props) => (
              <TextField {...props} helperText="selected time" />
            )}
          />
        </LocalizationProvider>

resulting in:
aria-label="Choose date and time, selected date and time is 07/23/2021 07:45 pm"

@eps1lon eps1lon changed the title a11y: TimePicker and DateTimePicker need to include time in aria-label [pickers] Include date/time in accessible name depending on picker variant Jul 24, 2021
@eps1lon eps1lon added accessibility a11y component: pickers This is the name of the generic UI component, not the React module! labels Jul 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

2 participants