Skip to content

Commit

Permalink
fix: remove the state functionality from setTabindex and add init con…
Browse files Browse the repository at this point in the history
…ditional
  • Loading branch information
sebnitu committed May 28, 2021
1 parent 4864d14 commit 5d48254
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dist/bundle.js.map

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions packages/core/src/js/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ export const setOverflowHidden = (state, selector) => {
}
};

export const setTabindex = (state, selector) => {
export const setTabindex = (selector) => {
if (selector) {
const els = document.querySelectorAll(selector);
els.forEach((el) => {
if (state) {
el.setAttribute('tabindex', '-1');
} else {
el.removeAttribute('tabindex');
}
el.setAttribute('tabindex', '-1');
});
}
};
16 changes: 6 additions & 10 deletions packages/core/tests/accessibility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,19 @@ describe('running setOverflowHidden', () => {
});

describe('running setTabindex', () => {
it('should apply overflow hidden to passed selectors', () => {
it('should do nothing if selector is not passed', () => {
expect(aside1).not.toHaveAttribute('tabindex');
expect(aside2).not.toHaveAttribute('tabindex');
setTabindex(true, '.aside');
expect(aside1).toHaveAttribute('tabindex', '-1');
expect(aside2).toHaveAttribute('tabindex', '-1');
});

it('should remove overflow hidden when set to false', () => {
setTabindex(false, '.aside');
setTabindex();
expect(aside1).not.toHaveAttribute('tabindex');
expect(aside2).not.toHaveAttribute('tabindex');
});

it('should do nothing if selector is not passed', () => {
setTabindex(true);
it('should apply overflow hidden to passed selectors', () => {
expect(aside1).not.toHaveAttribute('tabindex');
expect(aside2).not.toHaveAttribute('tabindex');
setTabindex('.aside');
expect(aside1).toHaveAttribute('tabindex', '-1');
expect(aside2).toHaveAttribute('tabindex', '-1');
});
});
8 changes: 5 additions & 3 deletions packages/drawer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default class Drawer {
init(options = null) {
if (options) this.settings = { ...this.settings, ...options };
this.stateSet();
this.setTabindex(this.settings.setTabindex);
if (this.settings.setTabindex) {
this.setTabindex();
}
this.breakpoint.init();
if (this.settings.eventListeners) {
this.initEventListeners();
Expand Down Expand Up @@ -76,12 +78,12 @@ export default class Drawer {
);
}

setTabindex(state = true) {
setTabindex() {
const selectorTabindex = `
[data-${this.settings.dataDrawer}]
[data-${this.settings.dataDialog}]
`;
setTabindex(state, selectorTabindex);
setTabindex(selectorTabindex);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export default class Modal {
init(options = null) {
if (options) this.settings = { ...this.settings, ...options };
this.moveModals();
this.setTabindex(this.settings.setTabindex);
if (this.settings.setTabindex) {
this.setTabindex();
}
this.setInitialState();
document.addEventListener('click', this.__handlerClick, false);
document.addEventListener('touchend', this.__handlerClick, false);
Expand Down Expand Up @@ -54,12 +56,12 @@ export default class Modal {
);
}

setTabindex(state = true) {
setTabindex() {
const selectorTabindex = `
[data-${this.settings.dataModal}]
[data-${this.settings.dataDialog}]
`;
setTabindex(state, selectorTabindex);
setTabindex(selectorTabindex);
}

setInitialState() {
Expand Down

0 comments on commit 5d48254

Please sign in to comment.