Skip to content

Commit

Permalink
test(maintain/disabled): remember disabled elements for disengage
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Feb 21, 2016
1 parent 7a168a2 commit 98c63c5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -59,6 +59,7 @@ The following lists show the changes to the library grouped by domain.
#### Various

* fixing [`ally.maintain.disabled`][ally/maintain/disabled] to properly handle `tabindex` attribute changes
* fixing [`ally.maintain.disabled`][ally/maintain/disabled] to properly disengage within ShadowHosts - [issue #107](https://github.com/medialize/ally.js/issues/107), [PR #108](https://github.com/medialize/ally.js/pull/108)

#### Internals

Expand Down
1 change: 1 addition & 0 deletions docs/api/maintain/disabled.md
Expand Up @@ -52,6 +52,7 @@ A [`<service>`](../concepts.md#Service) interface, providing the `handle.disenga
## Changes

* Since `v#master` changing `tabindex` attribute values are properly handled.
* Since `v#master` the `disengage()` method reverts elements within ShadowHosts to their previous state.


## Notes
Expand Down
16 changes: 4 additions & 12 deletions src/maintain/disabled.js
Expand Up @@ -62,16 +62,9 @@ class InertSubtree {
}

undoElementInert(this._context);
this._inertElementCache.forEach((element) => {
const index = this._inertElementCache.indexOf(element);

if (index > -1) {
this._inertElementCache = this._inertElementCache.splice(index, 1);
}

undoElementInert(element);
});
this._inertElementCache.forEach((element) => undoElementInert(element));

this._inertElementCache = null;
this._filter = null;
this._context = null;
this._observer && this._observer.disconnect();
Expand Down Expand Up @@ -120,9 +113,8 @@ class InertSubtree {

const addedFocusableElements = this.listQueryFocusable(addedElements);
this.renderInert(addedFocusableElements);
} else if (mutation.type === 'attributes' && this.filterElements(mutation.target)) {
this._inertElementCache.push(mutation.target);
makeElementInert(mutation.target);
} else if (mutation.type === 'attributes') {
this.renderInert([mutation.target]);
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/unit/element.disabled.test.js
Expand Up @@ -92,6 +92,19 @@ define([
elementDisabled(element, false);
expect(element.hasAttribute('tabindex')).to.equal(false, 'after disable undo');
},
'double execution': function() {
var element = document.getElementById('non-input');
expect(element.getAttribute('tabindex')).to.equal('0', 'before disable');

elementDisabled(element, true);
expect(element.getAttribute('tabindex')).to.equal('-1', 'after disable');

elementDisabled(element, true);
expect(element.getAttribute('tabindex')).to.equal('-1', 'after second disable');

elementDisabled(element, false);
expect(element.getAttribute('tabindex')).to.equal('0', 'after disable undo');
},
'disable restores tabindex="0"': function() {
var element = document.getElementById('non-input');
expect(element.getAttribute('tabindex')).to.equal('0', 'before disable');
Expand Down
3 changes: 3 additions & 0 deletions test/unit/maintain.disabled.test.js
Expand Up @@ -155,6 +155,9 @@ define([
expect(handle.disengage).to.be.a('function');
expect(fixture.input.after.disabled).to.equal(false, 'in filter');
expect(fixture.input.first.disabled).to.equal(true, 'out of filter');

handle.disengage();
expect(fixture.input.first.disabled).to.equal(false, 'after disengage');
},
'concurrent instances': function() {
var container = fixture.add('<input type="text" id="dynamic-input">', 'dynamic-wrapper');
Expand Down

0 comments on commit 98c63c5

Please sign in to comment.