Skip to content

Commit

Permalink
Merge pull request #426 from MisRob/tabs-updates
Browse files Browse the repository at this point in the history
KTabsList: Fix incorrect focus state + add a new event
  • Loading branch information
marcellamaki authored Mar 7, 2023
2 parents 4b8f272 + fd80a74 commit a671f6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Releases are recorded as git tags in the [Github releases](https://github.com/learningequality/kolibri-design-system/releases) page.

## Develop (to become version 1.5.x)
- [#426] - Adds `'click'` event to `KTabsList`
- [#425] - Adds `pinned` and `notPinned` icons. Updates `cloud` icon to outline
- [#424] - Adds `laptop` `cloud `and `wifi` icons to KDS
- [#351] - Wrap `KCheckbox` default slot's content in <label>
Expand Down Expand Up @@ -30,6 +31,8 @@ Releases are recorded as git tags in the [Github releases](https://github.com/le
[#384]: https://github.com/learningequality/kolibri-design-system/pull/384
[#403]: https://github.com/learningequality/kolibri-design-system/pull/403
[#420]: https://github.com/learningequality/kolibri-design-system/pull/420
[#424]: https://github.com/learningequality/kolibri-design-system/pull/424
[#426]: https://github.com/learningequality/kolibri-design-system/pull/426

## Version 1.4.x

Expand Down
13 changes: 10 additions & 3 deletions lib/tabs/KTabsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,8 @@
if (activeRouteTab !== undefined) {
const activeRouteTabId = activeRouteTab.dataset.tabid;
this.emitActivate(activeRouteTabId);
this.focusedTabIdx = this.getTabIdx(activeRouteTabId);
}
});
} else {
this.focusedTabIdx = this.getTabIdx(this.activeTabId);
}
this.$el.addEventListener('keyup', this.onKeyUp);
},
Expand Down Expand Up @@ -247,6 +244,7 @@
},
onClick(tabId, navigate, event) {
this.focusedTabIdx = this.getTabIdx(tabId);
this.emitClick(tabId);
this.emitActivate(tabId);
if (navigate) {
navigate(event);
Expand All @@ -272,6 +270,15 @@
*/
this.$emit('activate', tabId);
},
emitClick(tabId) {
/**
* Emitted when a tab is clicked. Its payload is the active tab ID.
* When compared to the `activate` event, `click` is emitted only when
* a user is interacting with tabs, whereas `activate` can be emitted
* programatically in addition to user interaction.
*/
this.$emit('click', tabId);
},
},
};
Expand Down
7 changes: 7 additions & 0 deletions lib/tabs/__tests__/KTabsList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ describe(`KTabsList`, () => {
expect(wrapper.emitted().activate.length).toBe(2);
expect(wrapper.emitted().activate[1][0]).toBe('tabGroups');
});

it(`emits 'click' event with the tab id in the payload`, () => {
const links = wrapper.findAll('a');
links.at(2).trigger('click');
expect(wrapper.emitted().click.length).toBe(1);
expect(wrapper.emitted().click[0][0]).toBe('tabGroups');
});
});
});
});

0 comments on commit a671f6f

Please sign in to comment.