Skip to content

Commit

Permalink
changed logic to introduce an explicit isControlled variable in the…
Browse files Browse the repository at this point in the history
… `Tabs` component

per @alex-ju suggestion
  • Loading branch information
didoo committed Oct 10, 2023
1 parent cd3b11f commit 8fd10b9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/components/addon/components/hds/tabs/index.js
Expand Up @@ -16,17 +16,25 @@ export default class HdsTabsIndexComponent extends Component {
@tracked panelIds = [];
@tracked _selectedTabIndex = this.args.selectedTabIndex ?? 0;
@tracked selectedTabId;
@tracked isControlled;

constructor() {
super(...arguments);

// this is to determine if the "selected" tab logic is controlled in the consumers' code or is maintained as an internal state
this.isControlled = this.args.selectedTabIndex !== undefined;
}

get selectedTabIndex() {
if (this.args.selectedTabIndex !== undefined) {
if (this.isControlled) {
return this.args.selectedTabIndex;
} else {
return this._selectedTabIndex;
}
}

set selectedTabIndex(value) {
if (this.args.selectedTabIndex) {
if (this.isControlled) {
// noop
} else {
this._selectedTabIndex = value;
Expand Down

0 comments on commit 8fd10b9

Please sign in to comment.