Skip to content

Commit

Permalink
label and assorted a11y fixes to timestamp field (#5893)
Browse files Browse the repository at this point in the history
* label and assorted a11y fixes to timestamp field

* chnageset
  • Loading branch information
gwyneplaine committed Jun 11, 2021
1 parent ac7430c commit df7d7b6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-mugs-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-ui/fields': patch
---

Applied a11y fixes to DatePicker component.
5 changes: 5 additions & 0 deletions .changeset/sharp-beans-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields': patch
---

Fixed labels in timestamp field for better screen reader experience.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx jsx */

import { ButtonHTMLAttributes, forwardRef } from 'react';
import { jsx, useTheme } from '@keystone-ui/core';
import { jsx, useTheme, VisuallyHidden } from '@keystone-ui/core';
import { XIcon } from '@keystone-ui/icons/icons/XIcon';
import { CalendarIcon } from '@keystone-ui/icons/icons/CalendarIcon';
import { useInputTokens, useInputStyles } from '../..';
Expand Down Expand Up @@ -77,6 +77,7 @@ const ClearButton = (props: ButtonHTMLAttributes<HTMLButtonElement>) => {
}}
{...props}
>
<VisuallyHidden as="span">clear date value</VisuallyHidden>
<XIcon size="small" />
</Adornment>
);
Expand Down
13 changes: 10 additions & 3 deletions packages-next/fields/src/types/timestamp/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
FieldControllerConfig,
FieldProps,
} from '@keystone-next/types';
import { jsx, Inline, Stack } from '@keystone-ui/core';
import { jsx, Inline, Stack, VisuallyHidden } from '@keystone-ui/core';
import { FieldContainer, FieldLabel, TextInput, DatePicker, DateType } from '@keystone-ui/fields';
import { TextInputProps } from '@keystone-ui/fields/src/TextInput';
import {
Expand All @@ -27,6 +27,7 @@ interface TimePickerProps extends TextInputProps {
}

const TimePicker = ({
id,
autoFocus,
onBlur,
disabled,
Expand All @@ -36,6 +37,7 @@ const TimePicker = ({
}: TimePickerProps) => {
return (
<TextInput
id={id}
autoFocus={autoFocus}
maxLength={format === '24hr' ? 5 : 7}
disabled={disabled}
Expand Down Expand Up @@ -74,8 +76,8 @@ export const Field = ({
};

return (
<FieldContainer>
<FieldLabel>{field.label}</FieldLabel>
<FieldContainer as="fieldset">
<FieldLabel as="legend">{field.label}</FieldLabel>
{onChange ? (
<Stack>
<Inline gap="small">
Expand All @@ -93,7 +95,12 @@ export const Field = ({
{showValidation && showDateError(value.dateValue)}
</Stack>
<Stack>
<VisuallyHidden
as="label"
htmlFor={`${field.path}--time-input`}
>{`${field.label} time field`}</VisuallyHidden>
<TimePicker
id={`${field.path}--time-input`}
onBlur={() => setTouchedSecondInput(true)}
disabled={onChange === undefined}
format="24hr"
Expand Down

1 comment on commit df7d7b6

@vercel
Copy link

@vercel vercel bot commented on df7d7b6 Jun 11, 2021

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.