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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/categories block label missing #10912

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions packages/block-library/src/categories/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { Component, Fragment } from '@wordpress/element';
import { PanelBody, Placeholder, Spinner, ToggleControl } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { times, unescape } from 'lodash';
import { withInstanceId, compose } from '@wordpress/compose';
import {
InspectorControls,
BlockControls,
BlockAlignmentToolbar,
} from '@wordpress/editor';
import { times, unescape } from 'lodash';

class CategoriesEdit extends Component {
constructor() {
Expand Down Expand Up @@ -106,14 +107,18 @@ class CategoriesEdit extends Component {
}

renderCategoryDropdown() {
const { showHierarchy } = this.props.attributes;
const { showHierarchy, instanceId, className } = this.props;
const parentId = showHierarchy ? 0 : null;
const categories = this.getCategories( parentId );

return (
<select className={ `${ this.props.className }__dropdown` }>
{ categories.map( ( category ) => this.renderCategoryDropdownItem( category, 0 ) ) }
</select>
<Fragment>
<label htmlFor={ `${ className }-${ instanceId }` } className="screen-reader-text">
{ __( 'Categories' ) }
</label>
<select id={ `${ className }-${ instanceId }` } className={ `${ className }__dropdown` }>
Copy link
Member

@gziolo gziolo Oct 23, 2018

Choose a reason for hiding this comment

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

I think id can be statically set in here to something like:

const selectId = `category-categories-select-${ instanceId }`;
...
<label htmlFor={ selectId } className="screen-reader-text">
....
<select id={ selectId } className={ `${ className }__dropdown` }>

Copy link
Contributor Author

@Luciaisacomputer Luciaisacomputer Oct 23, 2018

Choose a reason for hiding this comment

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

Thanks for the feedback, I'll make this change and push a commit when I find some time later today.

{ categories.map( ( category ) => this.renderCategoryDropdownItem( category, 0 ) ) }
</select>
</Fragment>
);
}

Expand Down Expand Up @@ -201,14 +206,16 @@ class CategoriesEdit extends Component {
);
}
}

export default withSelect( ( select ) => {
const { getEntityRecords } = select( 'core' );
const { isResolving } = select( 'core/data' );
const query = { per_page: -1 };

return {
categories: getEntityRecords( 'taxonomy', 'category', query ),
isRequesting: isResolving( 'core', 'getEntityRecords', [ 'taxonomy', 'category', query ] ),
};
} )( CategoriesEdit );
export default compose(
withSelect( ( select ) => {
const { getEntityRecords } = select( 'core' );
const { isResolving } = select( 'core/data' );
const query = { per_page: -1 };

return {
categories: getEntityRecords( 'taxonomy', 'category', query ),
isRequesting: isResolving( 'core', 'getEntityRecords', [ 'taxonomy', 'category', query ] ),
};
} ),
withInstanceId
)( CategoriesEdit );