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: Focus loss on navigation link label editing on Firefox. #52428

Merged
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
20 changes: 17 additions & 3 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export default function NavigationLinkEdit( {
const itemLabelPlaceholder = __( 'Add label…' );
const ref = useRef();

// Change the label using inspector causes rich text to change focus on firefox.
// This is a workaround to keep the focus on the label field when label filed is focused we don't render the rich text.
const [ isLabelFieldFocused, setIsLabelFieldFocused ] = useState( false );

const {
innerBlocks,
isAtMaxNesting,
Expand Down Expand Up @@ -424,6 +428,8 @@ export default function NavigationLinkEdit( {
} }
label={ __( 'Label' ) }
autoComplete="off"
onFocus={ () => setIsLabelFieldFocused( true ) }
onBlur={ () => setIsLabelFieldFocused( false ) }
/>
<TextControl
__nextHasNoMarginBottom
Expand Down Expand Up @@ -492,7 +498,9 @@ export default function NavigationLinkEdit( {
</div>
) : (
<>
{ ! isInvalid && ! isDraft && (
{ ! isInvalid &&
! isDraft &&
! isLabelFieldFocused && (
<>
<RichText
ref={ ref }
Expand Down Expand Up @@ -537,7 +545,9 @@ export default function NavigationLinkEdit( {
) }
</>
) }
{ ( isInvalid || isDraft ) && (
{ ( isInvalid ||
isDraft ||
isLabelFieldFocused ) && (
<div className="wp-block-navigation-link__placeholder-text wp-block-navigation-link__label">
<Tooltip
position="top center"
Expand All @@ -557,7 +567,11 @@ export default function NavigationLinkEdit( {
// See `updateAttributes` for more details.
`${ decodeEntities(
label
) } ${ placeholderText }`.trim()
) } ${
isInvalid || isDraft
? placeholderText
: ''
}`.trim()
}
</span>
<span className="wp-block-navigation-link__missing_text-tooltip">
Expand Down