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: Accessibility issue with links listing blocks. #(64051) #66866

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
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: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,8 @@ A cloud of popular keywords, each sized by how often it appears. ([Source](https

- **Name:** core/tag-cloud
- **Category:** widgets
- **Supports:** align, interactivity (clientNavigation), spacing (margin, padding), typography (lineHeight), ~~html~~
- **Attributes:** largestFontSize, numberOfTags, showTagCounts, smallestFontSize, taxonomy
- **Supports:** align, ariaLabel, interactivity (clientNavigation), spacing (margin, padding), typography (lineHeight), ~~html~~
- **Attributes:** ariaLabel, largestFontSize, numberOfTags, showTagCounts, smallestFontSize, taxonomy

## Template Part

Expand Down
10 changes: 6 additions & 4 deletions packages/block-library/src/categories/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default function CategoriesEdit( {

const TagName =
!! categories?.length && ! displayAsDropdown && ! isResolving
? 'ul'
? 'nav'
: 'div';

const classes = clsx( className, {
Expand Down Expand Up @@ -257,9 +257,11 @@ export default function CategoriesEdit( {
) }
{ ! isResolving &&
categories?.length > 0 &&
( displayAsDropdown
? renderCategoryDropdown()
: renderCategoryList() ) }
( displayAsDropdown ? (
renderCategoryDropdown()
) : (
<ul>{ renderCategoryList() }</ul>
) ) }
carolinan marked this conversation as resolved.
Show resolved Hide resolved
</TagName>
);
}
2 changes: 1 addition & 1 deletion packages/block-library/src/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function render_block_core_categories( $attributes, $content, $block ) {
} else {
$args['show_option_none'] = $taxonomy->labels->no_terms;

$wrapper_markup = '<ul %1$s>%2$s</ul>';
$wrapper_markup = '<nav %1$s><ul>%2$s</ul></nav>';
$items_markup = wp_list_categories( $args );
$type = 'list';

Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/tag-cloud/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"largestFontSize": {
"type": "string",
"default": "22pt"
},
"ariaLabel": {
"type": "string",
"default": "Tag Cloud"
}
},
"styles": [
Expand All @@ -52,6 +56,7 @@
"interactivity": {
"clientNavigation": true
},
"ariaLabel": true,
"__experimentalBorder": {
"radius": true,
"color": true,
Expand Down
165 changes: 92 additions & 73 deletions packages/block-library/src/tag-cloud/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
__experimentalVStack as VStack,
Disabled,
TextControl,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -48,6 +49,7 @@ function TagCloudEdit( { attributes, setAttributes } ) {
numberOfTags,
smallestFontSize,
largestFontSize,
ariaLabel,
} = attributes;

const [ availableUnits ] = useSettings( 'spacing.units' );
Expand Down Expand Up @@ -107,6 +109,10 @@ function TagCloudEdit( { attributes, setAttributes } ) {
setAttributes( updateObj );
};

const onChangeAriaLabel = ( value ) => {
setAttributes( { ariaLabel: value } );
};

// Remove border styles from the server-side attributes to prevent duplicate border.
const serverSideAttributes = {
...attributes,
Expand All @@ -117,79 +123,92 @@ function TagCloudEdit( { attributes, setAttributes } ) {
};

const inspectorControls = (
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<VStack
spacing={ 4 }
className="wp-block-tag-cloud__inspector-settings"
>
<SelectControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Taxonomy' ) }
options={ getTaxonomyOptions() }
value={ taxonomy }
onChange={ ( selectedTaxonomy ) =>
setAttributes( { taxonomy: selectedTaxonomy } )
}
/>
<Flex gap={ 4 }>
<FlexItem isBlock>
<UnitControl
label={ __( 'Smallest size' ) }
value={ smallestFontSize }
onChange={ ( value ) => {
onFontSizeChange(
'smallestFontSize',
value
);
} }
units={ units }
min={ MIN_FONT_SIZE }
max={ MAX_FONT_SIZE }
size="__unstable-large"
/>
</FlexItem>
<FlexItem isBlock>
<UnitControl
label={ __( 'Largest size' ) }
value={ largestFontSize }
onChange={ ( value ) => {
onFontSizeChange(
'largestFontSize',
value
);
} }
units={ units }
min={ MIN_FONT_SIZE }
max={ MAX_FONT_SIZE }
size="__unstable-large"
/>
</FlexItem>
</Flex>
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Number of tags' ) }
value={ numberOfTags }
onChange={ ( value ) =>
setAttributes( { numberOfTags: value } )
}
min={ MIN_TAGS }
max={ MAX_TAGS }
required
/>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show tag counts' ) }
checked={ showTagCounts }
onChange={ () =>
setAttributes( { showTagCounts: ! showTagCounts } )
}
/>
</VStack>
</PanelBody>
</InspectorControls>
<>
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<VStack
spacing={ 4 }
className="wp-block-tag-cloud__inspector-settings"
>
<SelectControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Taxonomy' ) }
options={ getTaxonomyOptions() }
value={ taxonomy }
onChange={ ( selectedTaxonomy ) =>
setAttributes( { taxonomy: selectedTaxonomy } )
}
/>
<Flex gap={ 4 }>
<FlexItem isBlock>
<UnitControl
label={ __( 'Smallest size' ) }
value={ smallestFontSize }
onChange={ ( value ) => {
onFontSizeChange(
'smallestFontSize',
value
);
} }
units={ units }
min={ MIN_FONT_SIZE }
max={ MAX_FONT_SIZE }
size="__unstable-large"
/>
</FlexItem>
<FlexItem isBlock>
<UnitControl
label={ __( 'Largest size' ) }
value={ largestFontSize }
onChange={ ( value ) => {
onFontSizeChange(
'largestFontSize',
value
);
} }
units={ units }
min={ MIN_FONT_SIZE }
max={ MAX_FONT_SIZE }
size="__unstable-large"
/>
</FlexItem>
</Flex>
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Number of tags' ) }
value={ numberOfTags }
onChange={ ( value ) =>
setAttributes( { numberOfTags: value } )
}
min={ MIN_TAGS }
max={ MAX_TAGS }
required
/>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show tag counts' ) }
checked={ showTagCounts }
onChange={ () =>
setAttributes( {
showTagCounts: ! showTagCounts,
} )
}
/>
</VStack>
</PanelBody>
</InspectorControls>
<InspectorControls group="advanced">
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Tag Cloud Name' ) }
value={ ariaLabel }
onChange={ onChangeAriaLabel }
/>
</InspectorControls>
</>
);

return (
Expand Down
6 changes: 5 additions & 1 deletion packages/block-library/src/tag-cloud/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
function render_block_core_tag_cloud( $attributes ) {
$smallest_font_size = $attributes['smallestFontSize'];
$unit = ( preg_match( '/^[0-9.]+(?P<unit>[a-z%]+)$/i', $smallest_font_size, $m ) ? $m['unit'] : 'pt' );
$aria_label = isset( $attributes['ariaLabel'] ) ? $attributes['ariaLabel'] : 'Tag Cloud';

$args = array(
'echo' => false,
Expand All @@ -40,9 +41,12 @@ function render_block_core_tag_cloud( $attributes ) {

$wrapper_attributes = get_block_wrapper_attributes();

$aria_label_attribute = 'aria-label="' . esc_attr( $aria_label ) . '" ';

return sprintf(
'<p %1$s>%2$s</p>',
'<nav %1$s %2$s>%3$s</nav>',
$wrapper_attributes,
$aria_label_attribute,
$tag_cloud
);
}
Expand Down
Loading