-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/form toggle accessibility #909
Changes from all commits
915e0ad
adf7ca5
f78ecc5
d3635b8
1a2c89b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { connect } from 'react-redux'; | |
* WordPress dependencies | ||
*/ | ||
import { __ } from 'i18n'; | ||
import { Component } from 'element'; | ||
import PanelBody from 'components/panel/body'; | ||
import FormToggle from 'components/form-toggle'; | ||
|
||
|
@@ -20,45 +21,55 @@ import PostSchedule from '../post-schedule'; | |
import { getEditedPostStatus, getSuggestedPostFormat } from '../../selectors'; | ||
import { editPost } from '../../actions'; | ||
|
||
function PostStatus( { status, onUpdateStatus, suggestedFormat } ) { | ||
const onToggle = () => { | ||
const updatedStatus = status === 'pending' ? 'draft' : 'pending'; | ||
onUpdateStatus( updatedStatus ); | ||
}; | ||
class PostStatus extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
this.id = this.constructor.instances++; | ||
} | ||
|
||
render() { | ||
const { status, onUpdateStatus, suggestedFormat } = this.props; | ||
const onToggle = () => { | ||
const updatedStatus = status === 'pending' ? 'draft' : 'pending'; | ||
onUpdateStatus( updatedStatus ); | ||
}; | ||
|
||
// Use the suggested post format based on the blocks content of the post | ||
// or the default post format setting for the site. | ||
const format = suggestedFormat || __( 'Standard' ); | ||
// Use the suggested post format based on the blocks content of the post | ||
// or the default post format setting for the site. | ||
const format = suggestedFormat || __( 'Standard' ); | ||
const pendingId = 'pending-toggle-' + this.id; | ||
|
||
// Disable Reason: The input is inside the label, we shouldn't need the htmlFor | ||
/* eslint-disable jsx-a11y/label-has-for */ | ||
return ( | ||
<PanelBody title={ __( 'Status & Visibility' ) }> | ||
<label className="editor-post-status__row"> | ||
<span>{ __( 'Pending review' ) }</span> | ||
<FormToggle | ||
checked={ status === 'pending' } | ||
onChange={ onToggle } | ||
/> | ||
</label> | ||
<div className="editor-post-status__row"> | ||
<PostVisibility /> | ||
</div> | ||
<div className="editor-post-status__row"> | ||
<PostSchedule /> | ||
</div> | ||
<div className="editor-post-status__row"> | ||
<span>{ __( 'Post Format' ) }</span> | ||
<span>{ format }</span> | ||
</div> | ||
<div className="editor-post-status__row"> | ||
<PostTrash /> | ||
</div> | ||
</PanelBody> | ||
); | ||
/* eslint-enable jsx-a11y/label-has-for */ | ||
return ( | ||
<PanelBody title={ __( 'Status & Visibility' ) }> | ||
<div className="editor-post-status__row"> | ||
<label htmlFor={ pendingId }>{ __( 'Pending review' ) }</label> | ||
<FormToggle | ||
id={ pendingId } | ||
checked={ status === 'pending' } | ||
onChange={ onToggle } | ||
showHint={ false } | ||
/> | ||
</div> | ||
<div className="editor-post-status__row"> | ||
<PostVisibility /> | ||
</div> | ||
<div className="editor-post-status__row"> | ||
<PostSchedule /> | ||
</div> | ||
<div className="editor-post-status__row"> | ||
<span>{ __( 'Post Format' ) }</span> | ||
<span>{ format }</span> | ||
</div> | ||
<div className="editor-post-status__row"> | ||
<PostTrash /> | ||
</div> | ||
</PanelBody> | ||
); | ||
} | ||
} | ||
|
||
PostStatus.instances = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a terribly complex pattern, but unfortunate in how it forces a class component. What do you think about a higher-order component for convenience? function MyComponent( { id } ) {
return <div id={ id } />;
}
export default withUniqueId( 'prefix-' )( MyComponent ); Not to be solved here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funny, because I was thinking the exact same thing 👍 (maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly that it's necessary, but between the two I might prefer |
||
|
||
export default connect( | ||
( state ) => ( { | ||
status: getEditedPostStatus( state ), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the need for z-index? Does it need to be higher than a dialog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this is a trick to allows the
onChange
handler to trigger when we click on the invisible input.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh Higher than the dialog probably not. I'm updating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if some logical groupings in the
_z-index.scss
, even just a few comments, could help avoid this temptation of assigning it a value a little more than the next highest. Like "Relative Siblings", "Layout", "Dialogs", etc. We have some grouping already, but mostly by related components. Dunno if that's a more sustainable pattern than lower-to-highest. It's a difficult problem, and one which I don't think needs to be solved here, but I expect will continue to surface over time.Related discussion at #637
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I like the idea of grouping by "type" and inside the lowest type "relative siblings" group by related components.