Skip to content

Commit

Permalink
feat(TabBar): emit $tabChanged signal when selected tab is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
THoj13 authored and ImCoolNowRight committed Nov 16, 2023
1 parent 92b7f57 commit c7a0a66
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export default class TabBar extends Base {
this._isTabsFocused = true;
}

_selectedTabChange() {
_selectedTabChange(selected, prevSelected) {
this.fireAncestors('$tabChanged', selected, prevSelected, this);
if (
typeof this._tabContent === 'object' &&
typeof this._tabContent.then === 'function'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class Example extends lng.Component {

\* `TabBar` also accepts all properties supported by the [Row](/docs/components-row--basic) component. These properties will be applied to the Row which renders the Tabs

### Signals

- `$tabChanged`: each time the selected tab is changed, a signal named `$tabChanged` is emitted (via `fireAncestors`) with 3 arguments in the following order: the current selected tab, the previously selected tab, and an instance of the TabBar component

```js
fireAncestors('$tabChanged', selected, prevSelected, this);
```

### Style Properties

| name | type | description |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ describe('TabBar', () => {
expect(tabBar._Tabs.items[1].mode).toBe('unfocused');
});

it('should emit a $tabChanged signal when the selected tab changes', () => {
const prevSelected = tabBar.tag('Tabs').selected;
jest.spyOn(tabBar, 'fireAncestors');
expect(tabBar.fireAncestors).not.toHaveBeenCalled();

tabBar.tag('Tabs').selectNext();
const selected = tabBar.tag('Tabs').selected;

expect(tabBar.fireAncestors).toHaveBeenCalledWith(
'$tabChanged',
selected,
prevSelected,
tabBar
);
});

it('should propogate key events', () => {
const onUp = jest.fn();
const onDown = jest.fn();
Expand Down

0 comments on commit c7a0a66

Please sign in to comment.