Skip to content

Commit 042530f

Browse files
committed
fix(link): introduce local states to avoid cursor reset
1 parent de6fdef commit 042530f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/block-components/helpers/link/edit.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
*/
1212
import { __ } from '@wordpress/i18n'
1313
import { useAttributeEditHandlers } from '~stackable/hooks'
14+
import { useState } from '@wordpress/element'
1415

1516
export const LinkControls = props => {
1617
const {
@@ -23,9 +24,13 @@ export const LinkControls = props => {
2324

2425
const {
2526
getAttribute,
27+
updateAttribute,
2628
updateAttributeHandler,
2729
} = useAttributeEditHandlers( props.attrNameTemplate )
2830

31+
const [ rel, setRel ] = useState( getAttribute( 'rel' ) )
32+
const [ title, setTitle ] = useState( getAttribute( 'title' ) )
33+
2934
const url = getAttribute( 'url' ) || ''
3035

3136
const showGoogleMapHint = getAttribute( 'hasLightbox' ) &&
@@ -70,14 +75,20 @@ export const LinkControls = props => {
7075
<AdvancedTextControl
7176
label={ __( 'Link rel', i18n ) }
7277
help={ __( 'Link relationship keywords, e.g. nofollow noreferrer prefetch', i18n ) }
73-
value={ getAttribute( 'rel' ) }
74-
onChange={ updateAttributeHandler( 'rel' ) }
78+
value={ rel }
79+
onChange={ value => {
80+
setRel( value )
81+
updateAttribute( 'rel', value )
82+
} }
7583
/>
7684
{ ( hasTitle || getAttribute( 'hasTitle' ) ) && (
7785
<AdvancedTextControl
7886
label={ __( 'Link Title', i18n ) }
79-
value={ getAttribute( 'title' ) }
80-
onChange={ updateAttributeHandler( 'title' ) }
87+
value={ title }
88+
onChange={ value => {
89+
setTitle( value )
90+
updateAttribute( 'title', value )
91+
} }
8192
isDynamic={ true }
8293
isFormatType={ false }
8394
help={ __( 'Also used for lightbox caption', i18n ) }

0 commit comments

Comments
 (0)