mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
Update normalizeDataKey to match the spec (#29609)
This commit is contained in:
parent
639c405c65
commit
c62efc3ef6
2 changed files with 11 additions and 11 deletions
|
@ -26,7 +26,7 @@ function normalizeData(val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeDataKey(key) {
|
function normalizeDataKey(key) {
|
||||||
return key.replace(/[A-Z]/g, chr => chr.toLowerCase())
|
return key.replace(/[A-Z]/g, chr => `-${chr.toLowerCase()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Manipulator = {
|
const Manipulator = {
|
||||||
|
|
|
@ -24,13 +24,13 @@ describe('Manipulator', () => {
|
||||||
expect(div.getAttribute('data-key')).toEqual('value')
|
expect(div.getAttribute('data-key')).toEqual('value')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set data attribute in lower case', () => {
|
it('should set data attribute in kebab case', () => {
|
||||||
fixtureEl.innerHTML = '<div></div>'
|
fixtureEl.innerHTML = '<div></div>'
|
||||||
|
|
||||||
const div = fixtureEl.querySelector('div')
|
const div = fixtureEl.querySelector('div')
|
||||||
|
|
||||||
Manipulator.setDataAttribute(div, 'tEsT', 'value')
|
Manipulator.setDataAttribute(div, 'testKey', 'value')
|
||||||
expect(div.getAttribute('data-test')).toEqual('value')
|
expect(div.getAttribute('data-test-key')).toEqual('value')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -44,13 +44,13 @@ describe('Manipulator', () => {
|
||||||
expect(div.getAttribute('data-key')).toBeNull()
|
expect(div.getAttribute('data-key')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should remove data attribute in lower case', () => {
|
it('should remove data attribute in kebab case', () => {
|
||||||
fixtureEl.innerHTML = '<div data-testkey="value" ></div>'
|
fixtureEl.innerHTML = '<div data-test-key="value"></div>'
|
||||||
|
|
||||||
const div = fixtureEl.querySelector('div')
|
const div = fixtureEl.querySelector('div')
|
||||||
|
|
||||||
Manipulator.removeDataAttribute(div, 'tEStKeY')
|
Manipulator.removeDataAttribute(div, 'testKey')
|
||||||
expect(div.getAttribute('data-testkey')).toBeNull()
|
expect(div.getAttribute('data-test-key')).toBeNull()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -81,12 +81,12 @@ describe('Manipulator', () => {
|
||||||
expect(Manipulator.getDataAttribute(div, 'test')).toBeNull()
|
expect(Manipulator.getDataAttribute(div, 'test')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should get data attribute in lower case', () => {
|
it('should get data attribute in kebab case', () => {
|
||||||
fixtureEl.innerHTML = '<div data-test="value" ></div>'
|
fixtureEl.innerHTML = '<div data-test-key="value" ></div>'
|
||||||
|
|
||||||
const div = fixtureEl.querySelector('div')
|
const div = fixtureEl.querySelector('div')
|
||||||
|
|
||||||
expect(Manipulator.getDataAttribute(div, 'tEsT')).toEqual('value')
|
expect(Manipulator.getDataAttribute(div, 'testKey')).toEqual('value')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should normalize data', () => {
|
it('should normalize data', () => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue