Skip to content

Commit 66668fd

Browse files
authored
Merge pull request #708 from Abderahman88/v1-RichTextFirstLink
RichText anchor bug V1
2 parents 48bf0a5 + 57f7905 commit 66668fd

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/controls/richText/RichText.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
369369
}} />
370370

371371
<TextField label={strings.TextToDisplayLabel}
372-
value={this.state.insertUrlText || this.state.insertUrl}
372+
value={this.state.insertUrlText}
373373
onChanged={(newValue?: string) => {
374374
if (newValue !== this.state.insertUrl) {
375375
this.setState({
@@ -385,7 +385,7 @@ export class RichText extends React.Component<IRichTextProps, IRichTextState> {
385385
<Link className={`${styles.action} ${styles.unlinkButton}`} onClick={this.handleRemoveLink}>{strings.RemoveLinkLabel}</Link>
386386
)
387387
}
388-
<PrimaryButton className={styles.action} onClick={this.handleCreateLink} text={strings.SaveButtonLabel} />
388+
<PrimaryButton className={styles.action} onClick={this.handleCreateLink} text={strings.SaveButtonLabel} disabled={this.checkLinkUrl()} />
389389
<DefaultButton className={styles.action} onClick={this.closeDialog} text={strings.CancelButtonLabel} />
390390
</div>
391391
</DialogFooter>
@@ -569,7 +569,7 @@ id="DropDownStyles"
569569
<ReactQuill ref={this.linkQuill}
570570
placeholder={placeholder}
571571
modules={modules}
572-
value={text || ''}
572+
defaultValue={text || ''} //property value causes issues, defaultValue does not
573573
onChange={this.handleChange}
574574
onChangeSelection={this.handleChangeSelection}
575575
onFocus={this.handleOnFocus} />
@@ -690,7 +690,7 @@ id="DropDownStyles"
690690
}
691691

692692
if (cursorPosition > -1) {
693-
const textToInsert: string = this.state.insertUrlText !== undefined ? this.state.insertUrlText : this.state.insertUrl;
693+
const textToInsert: string = (this.state.insertUrlText !== undefined && this.state.insertUrlText !== "") ? this.state.insertUrlText : this.state.insertUrl;
694694
const urlToInsert: string = this.state.insertUrl;
695695
quill.insertText(cursorPosition, textToInsert);
696696
quill.setSelection(cursorPosition, textToInsert.length);
@@ -704,6 +704,17 @@ id="DropDownStyles"
704704
});
705705
}
706706

707+
/**
708+
* Disable Save-button if hyperlink is undefined or empty
709+
* This prevents the user of adding an empty hyperlink
710+
*/
711+
private checkLinkUrl = () => {
712+
if (this.state.insertUrl !== undefined && this.state.insertUrl != "") {
713+
return false;
714+
}
715+
return true;
716+
}
717+
707718
/**
708719
* Applies a format to the selection
709720
* @param name format name

0 commit comments

Comments
 (0)