Skip to content

Commit

Permalink
fix(tabs): fix handleArrowKey func when no tab are active
Browse files Browse the repository at this point in the history
  • Loading branch information
skhamvon authored and dpellier committed Jan 16, 2024
1 parent 6a20fac commit 6c70007
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { OsdsTabs } from '../osds-tabs';
class OdsTabsController {
protected component: OsdsTabs;

private _tabItems: (Array<OsdsTabBarItem & HTMLElement>) = [];
public _tabItems: (Array<OsdsTabBarItem & HTMLElement>) = [];

public get tabItems(): (Array<OsdsTabBarItem & HTMLElement>) {
return this._tabItems;
Expand Down Expand Up @@ -54,9 +54,14 @@ class OdsTabsController {

handleArrowKey(event: KeyboardEvent): void {
const currentSelectedTabIndex = this.tabItems.findIndex((tab) => tab.hasAttribute('active'));
if(currentSelectedTabIndex === 0 && event.code === 'ArrowLeft' ) {
if (currentSelectedTabIndex === -1 || typeof currentSelectedTabIndex === 'undefined' ) {
return;
}

if(currentSelectedTabIndex === 0 && event.code === 'ArrowLeft') {
return;
}

if(currentSelectedTabIndex === this.tabItems.length - 1 && event.code === 'ArrowRight' ) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export class OsdsTabs implements OdsTabsAttribute, OdsTabsEvent {
<Host>
<div class="tabs-nav-wrap"
onKeyDown={ this.handleArrowKey.bind(this) }>
<slot name='top' onSlotchange={(): Promise<void> => this.handleSlotChange() }/>
<slot name='top'/>
</div>
<slot />
<slot onSlotchange={(): Promise<void> => this.handleSlotChange() }/>
</Host>
);
}
Expand Down

0 comments on commit 6c70007

Please sign in to comment.