-
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
Make social icon navigation one arrow keypress #64883
Changes from all commits
90a870d
6b7667f
41a2708
22d205e
64ca1c9
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ import clsx from 'clsx'; | |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { DELETE, BACKSPACE } from '@wordpress/keycodes'; | ||
import { DELETE, BACKSPACE, ENTER } from '@wordpress/keycodes'; | ||
import { useDispatch } from '@wordpress/data'; | ||
|
||
import { | ||
|
@@ -16,14 +16,15 @@ import { | |
useBlockProps, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { useState } from '@wordpress/element'; | ||
import { useState, useRef } from '@wordpress/element'; | ||
import { | ||
Button, | ||
PanelBody, | ||
PanelRow, | ||
TextControl, | ||
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper, | ||
} from '@wordpress/components'; | ||
import { useMergeRefs } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { keyboardReturn } from '@wordpress/icons'; | ||
|
||
|
@@ -112,12 +113,19 @@ const SocialLinkEdit = ( { | |
iconBackgroundColorValue, | ||
} = context; | ||
const [ showURLPopover, setPopover ] = useState( false ); | ||
const classes = clsx( 'wp-social-link', 'wp-social-link-' + service, { | ||
'wp-social-link__is-incomplete': ! url, | ||
[ `has-${ iconColor }-color` ]: iconColor, | ||
[ `has-${ iconBackgroundColor }-background-color` ]: | ||
iconBackgroundColor, | ||
} ); | ||
const wrapperClasses = clsx( | ||
'wp-social-link', | ||
// Manually adding this class for backwards compatibility of CSS when moving the | ||
// blockProps from the li to the button: https://github.com/WordPress/gutenberg/pull/64883 | ||
'wp-block-social-link', | ||
'wp-social-link-' + service, | ||
{ | ||
'wp-social-link__is-incomplete': ! url, | ||
[ `has-${ iconColor }-color` ]: iconColor, | ||
[ `has-${ iconBackgroundColor }-background-color` ]: | ||
iconBackgroundColor, | ||
} | ||
); | ||
|
||
// Use internal state instead of a ref to make sure that the component | ||
// re-renders when the popover's anchor updates. | ||
|
@@ -131,11 +139,16 @@ const SocialLinkEdit = ( { | |
// spaces. The PHP render callback fallbacks to the social name as well. | ||
const socialLinkText = label.trim() === '' ? socialLinkName : label; | ||
|
||
const ref = useRef(); | ||
const blockProps = useBlockProps( { | ||
className: classes, | ||
style: { | ||
color: iconColorValue, | ||
backgroundColor: iconBackgroundColorValue, | ||
className: 'wp-block-social-link-anchor', | ||
ref: useMergeRefs( [ setPopoverAnchor, ref ] ), | ||
onClick: () => setPopover( true ), | ||
onKeyDown: ( event ) => { | ||
if ( event.keyCode === ENTER ) { | ||
event.preventDefault(); | ||
setPopover( true ); | ||
} | ||
Comment on lines
+147
to
+151
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 needs the |
||
}, | ||
} ); | ||
|
||
|
@@ -169,13 +182,27 @@ const SocialLinkEdit = ( { | |
onChange={ ( value ) => setAttributes( { rel: value } ) } | ||
/> | ||
</InspectorControls> | ||
<li { ...blockProps }> | ||
<button | ||
className="wp-block-social-link-anchor" | ||
ref={ setPopoverAnchor } | ||
onClick={ () => setPopover( true ) } | ||
aria-haspopup="dialog" | ||
> | ||
{ /* | ||
* Because the `<ul>` element has a role=document, the `<li>` is | ||
* not semantically correct, so adding role=presentation is cleaner. | ||
* https://github.com/WordPress/gutenberg/pull/64883#issuecomment-2472874551 | ||
*/ } | ||
<li | ||
role="presentation" | ||
className={ wrapperClasses } | ||
style={ { | ||
color: iconColorValue, | ||
backgroundColor: iconBackgroundColorValue, | ||
} } | ||
Comment on lines
+192
to
+196
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. These were all added via the blockProps before, so we're adding them manually to preserve their styles. |
||
> | ||
{ /* | ||
* Disable reason: The `button` ARIA role is redundant but | ||
* blockProps has a role of `document` automatically applied | ||
* which breaks the semantics of this button since it removes | ||
* the information about the popover. | ||
*/ | ||
/* eslint-disable jsx-a11y/no-redundant-roles */ } | ||
<button aria-haspopup="dialog" { ...blockProps } role="button"> | ||
<IconComponent /> | ||
<span | ||
className={ clsx( 'wp-block-social-link-label', { | ||
|
@@ -185,6 +212,7 @@ const SocialLinkEdit = ( { | |
{ socialLinkText } | ||
</span> | ||
</button> | ||
{ /* eslint-enable jsx-a11y/no-redundant-roles */ } | ||
{ isSelected && showURLPopover && ( | ||
<SocialLinkURLPopover | ||
url={ url } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,10 @@ | |
// This rule is duplicated from the style.scss and needs to be the same as there. | ||
padding: 0.25em; | ||
|
||
// Focus styles replicate the `@wordpress/components` button component. | ||
&:focus:not(:disabled) { | ||
border-radius: 2px; | ||
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); | ||
|
||
// Windows High Contrast mode will show this outline, but not the box-shadow. | ||
outline: 3px solid transparent; | ||
// Override the shared `.wp-block-social-link` class used on both the li and button | ||
// due to backwards compatibility from moving the blockProps from the li to the button. | ||
&:hover { | ||
transform: none; | ||
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. This only impacts the editor style. This transform is already applied via the LI, so all we're doing is preventing that transform from triggering twice. |
||
} | ||
} | ||
|
||
|
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.
wp-block-social-link
is the only one that was added, and although it's technically "wrong" as only the social link block should get this class, by adding it we greatly reduce the chance of breaking user's CSS and this class is also output on the LI on the frontend.