fix(a11y): correct label "for" references to fields (#1904)
This commit is contained in:
parent
422d0cbe2f
commit
955f94f72b
@ -150,6 +150,8 @@ class EditorControl extends React.Component {
|
|||||||
activeLabel: false,
|
activeLabel: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uniqueFieldId = uniqueId(`${this.props.field.get('name')}-field-`);
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
value,
|
value,
|
||||||
@ -176,7 +178,6 @@ class EditorControl extends React.Component {
|
|||||||
const widget = resolveWidget(widgetName);
|
const widget = resolveWidget(widgetName);
|
||||||
const fieldName = field.get('name');
|
const fieldName = field.get('name');
|
||||||
const fieldHint = field.get('hint');
|
const fieldHint = field.get('hint');
|
||||||
const uniqueFieldId = uniqueId();
|
|
||||||
const metadata = fieldsMetaData && fieldsMetaData.get(fieldName);
|
const metadata = fieldsMetaData && fieldsMetaData.get(fieldName);
|
||||||
const errors = fieldsErrors && fieldsErrors.get(fieldName);
|
const errors = fieldsErrors && fieldsErrors.get(fieldName);
|
||||||
return (
|
return (
|
||||||
@ -197,7 +198,7 @@ class EditorControl extends React.Component {
|
|||||||
{ [styles.labelActive]: this.state.styleActive },
|
{ [styles.labelActive]: this.state.styleActive },
|
||||||
{ [styles.labelError]: !!errors },
|
{ [styles.labelError]: !!errors },
|
||||||
)}
|
)}
|
||||||
htmlFor={fieldName + uniqueFieldId}
|
htmlFor={this.uniqueFieldId}
|
||||||
>
|
>
|
||||||
{field.get('label', field.get('name'))}
|
{field.get('label', field.get('name'))}
|
||||||
</label>
|
</label>
|
||||||
@ -213,7 +214,7 @@ class EditorControl extends React.Component {
|
|||||||
classNameLabelActive={styles.labelActive}
|
classNameLabelActive={styles.labelActive}
|
||||||
controlComponent={widget.control}
|
controlComponent={widget.control}
|
||||||
field={field}
|
field={field}
|
||||||
uniqueFieldId={uniqueFieldId}
|
uniqueFieldId={this.uniqueFieldId}
|
||||||
value={value}
|
value={value}
|
||||||
mediaPaths={mediaPaths}
|
mediaPaths={mediaPaths}
|
||||||
metadata={metadata}
|
metadata={metadata}
|
||||||
|
@ -237,7 +237,7 @@ export default class Widget extends Component {
|
|||||||
onAddAsset,
|
onAddAsset,
|
||||||
onRemoveInsertedMedia,
|
onRemoveInsertedMedia,
|
||||||
getAsset,
|
getAsset,
|
||||||
forID: field.get('name') + uniqueFieldId,
|
forID: uniqueFieldId,
|
||||||
ref: this.processInnerControlRef,
|
ref: this.processInnerControlRef,
|
||||||
classNameWrapper,
|
classNameWrapper,
|
||||||
classNameWidget,
|
classNameWidget,
|
||||||
|
@ -4,7 +4,7 @@ import styled, { css } from 'react-emotion';
|
|||||||
import ReactToggled from 'react-toggled';
|
import ReactToggled from 'react-toggled';
|
||||||
import { colors, colorsRaw, shadows, transitions } from './styles';
|
import { colors, colorsRaw, shadows, transitions } from './styles';
|
||||||
|
|
||||||
const ToggleContainer = styled.span`
|
const ToggleContainer = styled.button`
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@ -12,6 +12,10 @@ const ToggleContainer = styled.span`
|
|||||||
width: 40px;
|
width: 40px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
background: transparent;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ToggleHandle = styled.span`
|
const ToggleHandle = styled.span`
|
||||||
@ -40,6 +44,7 @@ const ToggleBackground = styled.span`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const Toggle = ({
|
const Toggle = ({
|
||||||
|
id,
|
||||||
active,
|
active,
|
||||||
onChange,
|
onChange,
|
||||||
onFocus,
|
onFocus,
|
||||||
@ -50,14 +55,17 @@ const Toggle = ({
|
|||||||
Handle = ToggleHandle,
|
Handle = ToggleHandle,
|
||||||
}) => (
|
}) => (
|
||||||
<ReactToggled on={active} onToggle={onChange}>
|
<ReactToggled on={active} onToggle={onChange}>
|
||||||
{({ on, getElementTogglerProps }) => (
|
{({ on, getTogglerProps }) => (
|
||||||
<Container
|
<Container
|
||||||
role="switch"
|
id={id}
|
||||||
aria-checked={on.toString()}
|
|
||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
className={className}
|
className={className}
|
||||||
{...getElementTogglerProps()}
|
{...getTogglerProps({
|
||||||
|
role: 'switch',
|
||||||
|
'aria-checked': on.toString(),
|
||||||
|
'aria-expanded': null,
|
||||||
|
})}
|
||||||
>
|
>
|
||||||
<Background isActive={on} />
|
<Background isActive={on} />
|
||||||
<Handle isActive={on} />
|
<Handle isActive={on} />
|
||||||
@ -67,6 +75,7 @@ const Toggle = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
Toggle.propTypes = {
|
Toggle.propTypes = {
|
||||||
|
id: PropTypes.string,
|
||||||
active: PropTypes.bool,
|
active: PropTypes.bool,
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
onFocus: PropTypes.func,
|
onFocus: PropTypes.func,
|
||||||
|
@ -12,6 +12,7 @@ injectGlobal`
|
|||||||
export default class DateControl extends React.Component {
|
export default class DateControl extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
field: PropTypes.object.isRequired,
|
field: PropTypes.object.isRequired,
|
||||||
|
forID: PropTypes.string,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
classNameWrapper: PropTypes.string.isRequired,
|
classNameWrapper: PropTypes.string.isRequired,
|
||||||
setActiveStyle: PropTypes.func.isRequired,
|
setActiveStyle: PropTypes.func.isRequired,
|
||||||
@ -102,7 +103,7 @@ export default class DateControl extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { value, classNameWrapper, setActiveStyle } = this.props;
|
const { forID, value, classNameWrapper, setActiveStyle } = this.props;
|
||||||
const { format, dateFormat, timeFormat } = this.formats;
|
const { format, dateFormat, timeFormat } = this.formats;
|
||||||
return (
|
return (
|
||||||
<DateTime
|
<DateTime
|
||||||
@ -112,7 +113,7 @@ export default class DateControl extends React.Component {
|
|||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
onFocus={setActiveStyle}
|
onFocus={setActiveStyle}
|
||||||
onBlur={this.onBlur}
|
onBlur={this.onBlur}
|
||||||
inputProps={{ className: classNameWrapper }}
|
inputProps={{ className: classNameWrapper, id: forID }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ export default class SelectControl extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
id={forID}
|
inputId={forID}
|
||||||
value={selectedValue}
|
value={selectedValue}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
className={classNameWrapper}
|
className={classNameWrapper}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user