1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-02 06:32:07 +02:00

feature: Remove support for setting nonstandard attributes as props (#7857)

* remove statement that handles attributes in props argument

* clean up function

* add unit test

* add unit test

* remove duplicate set attr

* revert function cleanup
This commit is contained in:
Roman Pougatchev 2022-07-28 16:44:53 -04:00 committed by Pat O'Neill
parent 706983caa3
commit f46b83002e
3 changed files with 15 additions and 12 deletions

View File

@ -133,8 +133,7 @@ class Slider extends Component {
'role': 'slider',
'aria-valuenow': 0,
'aria-valuemin': 0,
'aria-valuemax': 100,
'tabIndex': 0
'aria-valuemax': 100
}, attributes);
return super.createEl(type, props, attributes);

View File

@ -153,18 +153,9 @@ export function createEl(tagName = 'div', properties = {}, attributes = {}, cont
Object.getOwnPropertyNames(properties).forEach(function(propName) {
const val = properties[propName];
// See #2176
// We originally were accepting both properties and attributes in the
// same object, but that doesn't work so well.
if (propName.indexOf('aria-') !== -1 || propName === 'role' || propName === 'type') {
log.warn('Setting attributes in the second argument of createEl()\n' +
'has been deprecated. Use the third argument instead.\n' +
`createEl(type, properties, attributes). Attempting to set ${propName} to ${val}.`);
el.setAttribute(propName, val);
// Handle textContent since it's not supported everywhere and we have a
// method for it.
} else if (propName === 'textContent') {
if (propName === 'textContent') {
textContent(el, val);
} else if (el[propName] !== val || propName === 'tabIndex') {
el[propName] = val;

View File

@ -30,6 +30,12 @@ QUnit.test('should create an element, supporting textContent', function(assert)
}
});
QUnit.test('should create an element with tabIndex prop', function(assert) {
const span = Dom.createEl('span', {tabIndex: '5'});
assert.strictEqual(span.tabIndex, 5);
});
QUnit.test('should create an element with content', function(assert) {
const span = Dom.createEl('span');
const div = Dom.createEl('div', undefined, undefined, span);
@ -37,6 +43,13 @@ QUnit.test('should create an element with content', function(assert) {
assert.strictEqual(div.firstChild, span);
});
QUnit.test('should be able to set standard props as attributes, and vice versa, on a created element', function(assert) {
const span = Dom.createEl('span', {className: 'bar'}, {id: 'foo'});
assert.strictEqual(span.getAttribute('class'), 'bar');
assert.strictEqual(span.id, 'foo');
});
QUnit.test('should insert an element first in another', function(assert) {
const el1 = document.createElement('div');
const el2 = document.createElement('div');