Skip to content

Commit 299e3ee

Browse files
committed
Merge branch 'beta'
* beta: Fix text overflow caused by long URL (metabrainz#2216) Return focus to selector if type is not selected Fix adding relationship when link is not submitted Allow submitting form from empty URL input
2 parents a216f19 + 510d7b0 commit 299e3ee

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

root/static/scripts/edit/components/URLInputPopover.js

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const URLInputPopover = (props: PropsT): React.MixedElement => {
9696
className="clean-url"
9797
href={link.url}
9898
rel="noreferrer"
99+
style={{overflowWrap: 'anywhere'}}
99100
target="_blank"
100101
>
101102
{link.url}

root/static/scripts/edit/externalLinks.js

+27-8
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,22 @@ export class ExternalLinksEditor
202202
if (url !== '' && !error) {
203203
link.submitted = true;
204204
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+
}
210221
});
211222
} else {
212223
this.setLinkState(index, link);
@@ -771,7 +782,11 @@ type LinkProps = {
771782

772783
export class ExternalLink extends React.Component<LinkProps> {
773784
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+
*/
775790
event.preventDefault();
776791
this.props.handleLinkSubmit(event);
777792
}
@@ -833,6 +848,7 @@ export class ExternalLink extends React.Component<LinkProps> {
833848
className="url"
834849
href={props.url}
835850
rel="noreferrer"
851+
style={{overflowWrap: 'anywhere'}}
836852
target="_blank"
837853
>
838854
{props.url}
@@ -890,8 +906,11 @@ export class ExternalLink extends React.Component<LinkProps> {
890906
typeOptions={props.typeOptions}
891907
/>
892908
))}
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 &&
895914
<tr className="add-relationship">
896915
<td />
897916
<td className="add-item" colSpan="4">

0 commit comments

Comments
 (0)