Skip to content

Commit

Permalink
fix: helper.js classNames was overzealous in removing classNames star…
Browse files Browse the repository at this point in the history
…ting with btn- when syncing with style field, only remove those that are one of the config.js styles.btn styles
  • Loading branch information
lucasnetau committed Aug 24, 2023
1 parent 58baf4e commit 922ca80
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getAllGridRelatedClasses,
} from './utils'
import events from './events'
import { config, defaultTimeout } from './config'
import { config, defaultTimeout, styles } from './config'
import control from './control'
import controlCustom from './control/custom'
import storageAvailable from 'storage-available'
Expand Down Expand Up @@ -267,7 +267,8 @@ export default class Helpers {
}

if (fieldData.className) {
const match = /(?:^|\s)btn-(.*?)(?:\s|$)/g.exec(fieldData.className)
const regex = new RegExp('(?:^|\\s)btn-(' + styles.btn.join('|') + ')(?:\\s|$)', 'g')
const match = regex.exec(fieldData.className)
if (match) {
fieldData.style = match[1]
}
Expand Down Expand Up @@ -481,15 +482,14 @@ export default class Helpers {

if (primaryType && style) {
for (let i = 0; i < classes.length; i++) {
const re = new RegExp(`^${primaryType}-.*`, 'g')
const re = new RegExp(`^${primaryType}-(?:` + styles.btn.join('|') + ')$')
const match = classes[i].match(re)
if (match) {
classes.splice(i, 1, primaryType + '-' + style)
} else {
classes.push(primaryType + '-' + style)
}
}

classes.push(primaryType + '-' + style)
classes.push(primaryType)
}

Expand Down

0 comments on commit 922ca80

Please sign in to comment.