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: Frontend Category Label + Make Category and Archive Labels Visible #11219

Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/block-library/src/archives/editor.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.block-editor ul.wp-block-archives {
padding-left: 2.5em;
}

.block-editor .wp-block-archives__label {
display: block;
Copy link
Member

Choose a reason for hiding this comment

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

Should this not also be display: block; on the front-end?

This note applies to the categories block as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the time I think I wanted these to be as least opinionated as possible in themes but I can make these changes to render the controls in the same manner on the front end.

Copy link
Member

Choose a reason for hiding this comment

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

So why is it part of the editor styles in the first place?

}
4 changes: 3 additions & 1 deletion packages/block-library/src/archives/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ function render_block_core_archives( $attributes ) {

$label = esc_attr( $label );

$block_content = '<label class="screen-reader-text" for="' . $dropdown_id . '">' . $title . '</label>
Copy link
Member

@oandregal oandregal Nov 15, 2018

Choose a reason for hiding this comment

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

Is this necessary? Per #10871 (comment) it looks like we may want to keep this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I think I got a little eager with this PR, but essentially I felt it was necessary to make the labels visible because it will provide better context to all users. If we can get some design feedback, I can easily revert the removal of these classes. There was some discussion about this in the original issue for this. Maybe @afercia can also speak to why others felt it made sense to make the label visible.

$label_class = 'wp-block-archives__label';

$block_content = '<label class="' . $label_class . '" for="' . $dropdown_id . '">' . $title . '</label>
<select id="' . $dropdown_id . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">' . $label . '</option>' . $archives . '</select>';

Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/archives/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.wp-block-archives-dropdown {
Copy link
Member

Choose a reason for hiding this comment

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

This class is never actually assigned to the select on the front-end, so it's not applied.

This note applies to the categories block as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I thought these were being added with the below code:

$class = "wp-block-categories wp-block-categories-{$type}";

I'll take a look and see what I find out

Copy link
Contributor Author

@Luciaisacomputer Luciaisacomputer Jan 21, 2019

Choose a reason for hiding this comment

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

It looks like it is being applied but it has a low specificity compared to a bunch of other selectors.

margin-bottom: 1em;
}
2 changes: 1 addition & 1 deletion packages/block-library/src/categories/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class CategoriesEdit extends Component {
const selectId = `blocks-category-select-${ instanceId }`;
return (
<Fragment>
<label htmlFor={ selectId } className="screen-reader-text">
<label className={ `wp-block-categories__label` } htmlFor={ selectId }>
{ __( 'Categories' ) }
</label>
<select id={ selectId } className={ `${ className }__dropdown` }>
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/categories/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
margin-top: 6px;
}
}

.block-editor .wp-block-categories__label {
display: block;
}
3 changes: 3 additions & 0 deletions packages/block-library/src/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function render_block_core_categories( $attributes ) {
$wrapper_markup = '<div class="%1$s">%2$s</div>';
$items_markup = wp_dropdown_categories( $args );
$type = 'dropdown';
$title = esc_html( __( 'Categories' ) );
$label_class = 'wp-block-categories-label';
$items_markup = '<label class="' . $label_class . '" for="' . $id . '">' . $title . '</label> ' . $items_markup;
Copy link
Member

Choose a reason for hiding this comment

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

I believe $title ought to be escaped here, perhaps via esc_html__

https://developer.wordpress.org/reference/functions/esc_html__/


if ( ! is_admin() ) {
$wrapper_markup .= build_dropdown_script_block_core_categories( $id );
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/categories/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
margin-left: 2em;
}
}

.wp-block-categories-dropdown {
margin-bottom: 1em;
}
1 change: 1 addition & 0 deletions packages/block-library/src/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "./archives/style.scss";
@import "./audio/style.scss";
@import "./block/edit-panel/style.scss";
@import "./block/indicator/style.scss";
Expand Down