Skip to content

Commit

Permalink
Only allow links for selected text
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jan 24, 2024
1 parent 93cc5d6 commit 8ecc238
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/format-library/src/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function Edit( {
} ) {
const [ addingLink, setAddingLink ] = useState( false );

const canMakeLink = ! isCollapsed( value ) && ! addingLink && ! isActive;

function addLink() {
const text = getTextContent( slice( value ) );

Expand Down Expand Up @@ -76,7 +78,13 @@ function Edit( {

return (
<>
<RichTextShortcut type="primary" character="k" onUse={ addLink } />
{ canMakeLink && (
<RichTextShortcut
type="primary"
character="k"
onUse={ addLink }
/>
) }
<RichTextShortcut
type="primaryShift"
character="k"
Expand Down Expand Up @@ -106,6 +114,7 @@ function Edit( {
shortcutCharacter="k"
aria-haspopup="true"
aria-expanded={ addingLink || isActive }
disabled={ ! canMakeLink }
/>
) }
{ ( addingLink || isActive ) && (
Expand Down

0 comments on commit 8ecc238

Please sign in to comment.