Skip to content

Commit

Permalink
fix: correct the tabindex value (#18)
Browse files Browse the repository at this point in the history
Co-authored-by: kkmch <[email protected]>
  • Loading branch information
Kyzyl-ool and kkmch authored Sep 20, 2023
1 parent 201cdac commit 8b47bb2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ACTIVE_CLASSNAME = 'active';
export const GROUP_DATA_KEY = 'data-diplodoc-group';
export const TAB_DATA_KEY = 'data-diplodoc-key';
export const TAB_DATA_ID = 'data-diplodoc-id';
export const TAB_ACTIVA_KEY = 'data-diplodoc-is-active';
export const TAB_ACTIVE_KEY = 'data-diplodoc-is-active';

export const DEFAULT_TABS_GROUP_PREFIX = 'defaultTabsGroup-';

Expand Down
7 changes: 3 additions & 4 deletions src/plugin/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ACTIVE_CLASSNAME,
DEFAULT_TABS_GROUP_PREFIX,
GROUP_DATA_KEY,
TAB_ACTIVA_KEY,
TAB_ACTIVE_KEY,
TABS_CLASSNAME,
TABS_LIST_CLASSNAME,
TAB_CLASSNAME,
Expand Down Expand Up @@ -186,12 +186,12 @@ function insertTabs(
tabPanelClose.block = true;
tabOpen.attrSet(TAB_DATA_ID, tabId);
tabOpen.attrSet(TAB_DATA_KEY, tabKey);
tabOpen.attrSet(TAB_ACTIVA_KEY, i === 0 ? 'true' : 'false');
tabOpen.attrSet(TAB_ACTIVE_KEY, i === 0 ? 'true' : 'false');
tabOpen.attrSet('class', TAB_CLASSNAME);
tabOpen.attrSet('role', 'tab');
tabOpen.attrSet('aria-controls', tabPanelId);
tabOpen.attrSet('aria-selected', 'false');
tabOpen.attrSet('tabindex', '-1');
tabOpen.attrSet('tabindex', i === 0 ? '-1' : '0');
tabPanelOpen.attrSet('id', tabPanelId);
tabPanelOpen.attrSet('class', TAB_PANEL_CLASSNAME);
tabPanelOpen.attrSet('role', 'tabpanel');
Expand All @@ -201,7 +201,6 @@ function insertTabs(
if (i === 0) {
tabOpen.attrJoin('class', ACTIVE_CLASSNAME);
tabOpen.attrSet('aria-selected', 'true');
tabOpen.attrSet('tabindex', '0');
tabPanelOpen.attrJoin('class', ACTIVE_CLASSNAME);
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/TabsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class TabsController {

tab.classList.toggle(ACTIVE_CLASSNAME, isTargetTab);
tab.setAttribute('aria-selected', isTargetTab.toString());
tab.setAttribute('tabindex', isTargetTab ? '0' : '-1');
tab.setAttribute('tabindex', isTargetTab ? '-1' : '0');
panel.classList.toggle(ACTIVE_CLASSNAME, isTargetTab);
});
});
Expand Down
1 change: 1 addition & 0 deletions test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('plugin', () => {
expect(Object.keys(attrsObject)).toEqual(attrs);
expect(attrsObject['class']).toEqual(`yfm-tab${i === 0 ? ' active' : ''}`);
expect(attrsObject['role']).toEqual('tab');
expect(attrsObject['tabindex']).toEqual(i === 0 ? '-1' : '0');
});
});

Expand Down

0 comments on commit 8b47bb2

Please sign in to comment.