Skip to content

Commit

Permalink
fix(core): fix error when merging class attributes (#4340)
Browse files Browse the repository at this point in the history
* fix(core): fix error when merging class attributes
* added test
  • Loading branch information
bdbch authored Aug 17, 2023
1 parent 141dd26 commit a251946
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions demos/src/Marks/Link/React/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Link from '@tiptap/extension-link'

context('/src/Marks/Link/React/', () => {
before(() => {
cy.visit('/src/Marks/Link/React/')
Expand All @@ -10,6 +12,18 @@ context('/src/Marks/Link/React/', () => {
})
})

it('should add a custom class to a link', () => {
const linkExtension = Link.configure({
HTMLAttributes: {
class: 'foo',
},
})

expect(linkExtension.options.HTMLAttributes).to.deep.include({
class: 'foo',
})
})

it('should parse a tags correctly', () => {
cy.get('.tiptap').then(([{ editor }]) => {
editor.commands.setContent('<p><a href="#">Example Text</a></p>')
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utilities/mergeAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export function mergeAttributes(...objects: Record<string, any>[]): Record<strin
}

if (key === 'class') {
const valueClasses: string[] = value.split(' ')
const existingClasses: string[] = mergedAttributes[key].split(' ')
const valueClasses: string[] = value ? value.split(' ') : []
const existingClasses: string[] = mergedAttributes[key] ? mergedAttributes[key].split(' ') : []

const insertClasses = valueClasses.filter(
valueClass => !existingClasses.includes(valueClass),
Expand Down

0 comments on commit a251946

Please sign in to comment.