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

Fix setTabindex from removing tabindex attributes when set to false #603

Merged
merged 1 commit into from
May 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
if (this.settings.eventListeners) {
this.initEventListeners();
Expand Down Expand Up @@ -70,12 +72,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