Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link title is correctly applied through the command #5191

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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