Skip to content
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
1 change: 1 addition & 0 deletions src/block-components/block-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ BlockLink.Content = props => {
target={ attributes.blockLinkNewTab ? '_blank' : '' }
rel={ attributes.blockLinkRel || undefined }
title={ attributes.blockLinkTitle || undefined }
aria-label={ attributes.blockLinkAriaLabel || undefined }
aria-hidden={ isHidden ? 'true' : undefined }
tabindex={ isHidden ? '-1' : undefined }
/>
Expand Down
15 changes: 15 additions & 0 deletions src/block-components/helpers/link/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,19 @@ export const addLinkAttributes = ( attrObject, attrNameTemplate = '%s', selector
versionAdded: '3.0.0',
versionDeprecated: '',
} )

attrObject.add( {
attributes: {
ariaLabel: {
type: 'string',
source: 'attribute',
selector,
attribute: 'aria-label',
default: '',
},
},
attrNameTemplate,
versionAdded: '3.20.1',
versionDeprecated: '',
} )
}
9 changes: 9 additions & 0 deletions src/block-components/helpers/link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const LinkControls = props => {
const hasLightboxAttr = useAttributeValue( 'hasLightbox', props.attrNameTemplate )
const rel = useAttributeValue( 'rel', props.attrNameTemplate )
const title = useAttributeValue( 'title', props.attrNameTemplate )
const ariaLabel = useAttributeValue( 'ariaLabel', props.attrNameTemplate )
const hasTitleAttr = useAttributeValue( 'hasTitle', props.attrNameTemplate )

const showGoogleMapHint = hasLightboxAttr &&
Expand Down Expand Up @@ -76,6 +77,14 @@ export const LinkControls = props => {
value={ rel }
onChange={ updateAttributeHandler( 'rel' ) }
/>
<AdvancedTextControl
label={ __( 'Link accessibility label', i18n ) }
help={ __( 'Describe the purpose of the link for screen reader users.', i18n ) }
value={ ariaLabel }
onChange={ updateAttributeHandler( 'ariaLabel' ) }
isDynamic={ true }
isFormatType={ false }
/>
{ ( hasTitle || hasTitleAttr ) && (
<AdvancedTextControl
label={ __( 'Link Title', i18n ) }
Expand Down
2 changes: 1 addition & 1 deletion src/block-components/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Link.Content = props => {
target={ attributes.linkNewTab ? '_blank' : undefined }
rel={ attributes.linkRel || undefined }
title={ attributes.linkTitle || undefined }
aria-label={ attributes.linkAriaLabel || undefined }
>
{ props.children }
</LinkComponent.Content>
Expand All @@ -64,4 +65,3 @@ Link.Content = props => {
Link.InspectorControls = Edit

Link.addAttributes = addAttributes

Loading