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

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

Merged
merged 6 commits into from
Jul 28, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/js/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 1 addition & 10 deletions src/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/unit/utils/dom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@ 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);

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');
Expand Down