Skip to content

Commit

Permalink
Link title is correclty applied through the command
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Nov 2, 2023
1 parent dc2da3a commit e7682a0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion packages/lexical-link/src/__tests__/unit/LexicalLinkNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@
*
*/

import {$createLinkNode, $isLinkNode, LinkNode} from '@lexical/link';
import {
$createLinkNode,
$isLinkNode,
LinkNode,
SerializedLinkNode,
toggleLink,
} from '@lexical/link';
import {
$getRoot,
$selectAll,
ParagraphNode,
SerializedParagraphNode,
TextNode,
} from 'lexical/src';
import {initializeUnitTest} from 'lexical/src/__tests__/utils';

const editorConfig = Object.freeze({
Expand Down Expand Up @@ -377,5 +390,24 @@ describe('LexicalLinkNode tests', () => {
expect($isLinkNode(linkNode)).toBe(true);
});
});

test('toggleLink applies the title attribute when creating', async () => {
const {editor} = testEnv;
await editor.update(() => {
const p = new ParagraphNode();
p.append(new TextNode('Some text'));
$getRoot().append(p);
});

await editor.update(() => {
$selectAll();
toggleLink('https://lexical.dev/', {title: 'Lexical Website'});
});

const paragraph = editor!.getEditorState().toJSON().root
.children[0] as SerializedParagraphNode;
const link = paragraph.children[0] as SerializedLinkNode;
expect(link.title).toBe('Lexical Website');
});
});
});
2 changes: 1 addition & 1 deletion packages/lexical-link/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export function toggleLink(

if (!parent.is(prevParent)) {
prevParent = parent;
linkNode = $createLinkNode(url, {rel, target});
linkNode = $createLinkNode(url, {rel, target, title});

if ($isLinkNode(parent)) {
if (node.getPreviousSibling() === null) {
Expand Down

0 comments on commit e7682a0

Please sign in to comment.