@@ -202,11 +202,22 @@ export class ExternalLinksEditor
202
202
if ( url !== '' && ! error ) {
203
203
link . submitted = true ;
204
204
this . setLinkState ( index , link , ( ) => {
205
- // Redirect focus to the 'x' icon instead of the link
206
- $ ( this . tableRef . current )
207
- . find ( `tr.external-link-item:eq(${ urlIndex } )` )
208
- . find ( 'button.remove-item' )
209
- . focus ( ) ;
205
+ // Redirect focus instead of staying on the current link
206
+ if ( link . type ) {
207
+ // If type is selected, jump to the next item(either input or link)
208
+ $ ( this . tableRef . current )
209
+ . find ( `tr.external-link-item:eq(${ urlIndex + 1 } )` )
210
+ . find ( 'a,input' )
211
+ . eq ( 0 )
212
+ . focus ( ) ;
213
+ } else {
214
+ // If type is not selected, jump to type selector
215
+ $ ( this . tableRef . current )
216
+ . find ( `tr.external-link-item:eq(${ urlIndex } )
217
+ + tr.relationship-item` )
218
+ . find ( 'select.link-type' )
219
+ . focus ( ) ;
220
+ }
210
221
} ) ;
211
222
} else {
212
223
this . setLinkState ( index , link ) ;
@@ -771,7 +782,11 @@ type LinkProps = {
771
782
772
783
export class ExternalLink extends React . Component < LinkProps > {
773
784
handleKeyDown ( event : SyntheticKeyboardEvent < HTMLInputElement > ) {
774
- if ( event . key === 'Enter' ) {
785
+ if ( event . key === 'Enter' && this . props . url ) {
786
+ /*
787
+ * If there's a link, prevent default and submit it,
788
+ * otherwise allow submitting the form from empty field.
789
+ */
775
790
event . preventDefault ( ) ;
776
791
this . props . handleLinkSubmit ( event ) ;
777
792
}
@@ -833,6 +848,7 @@ export class ExternalLink extends React.Component<LinkProps> {
833
848
className = "url"
834
849
href = { props . url }
835
850
rel = "noreferrer"
851
+ style = { { overflowWrap : 'anywhere' } }
836
852
target = "_blank"
837
853
>
838
854
{ props . url }
@@ -890,8 +906,11 @@ export class ExternalLink extends React.Component<LinkProps> {
890
906
typeOptions = { props . typeOptions }
891
907
/>
892
908
) ) }
893
- { /* Hide the button when link type is auto-selected */ }
894
- { notEmpty && ! firstLink . urlMatchesType &&
909
+ { /*
910
+ * Hide the button when link is not submitted
911
+ * or link type is auto-selected.
912
+ */ }
913
+ { notEmpty && firstLink . submitted && ! firstLink . urlMatchesType &&
895
914
< tr className = "add-relationship" >
896
915
< td />
897
916
< td className = "add-item" colSpan = "4" >
0 commit comments