Skip to content

Commit

Permalink
Merge pull request #189 from US-CBP/bugfix/tabs-selected-error
Browse files Browse the repository at this point in the history
bugfix/tabs-selected-error
  • Loading branch information
dgibson666 authored Aug 27, 2024
2 parents 1fb09d2 + 73137a5 commit c02218f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ export class CbpTabPanel {

@Element() host: HTMLElement;

/** An `ID`-conformant unique name of the tab; This value should match the corresponding cbp-tab-panel name and links the two together. */
@Prop() name: string;
/** An `ID`-conformant unique name of the tab-panel, applied as an `id` on this tab panel; This value should match the corresponding cbp-tab name and links the two together. */
@Prop() name!: string;

/** Specifies if this is the tab panel corresponding to the selected tab and currently visible. This property is managed by the parent cbp-tabs component and does not need to be set manually. */
@Prop({ reflect: true }) selected: boolean;

/** Supports adding inline styles as an object */
@Prop() sx: any = {};


componentWillLoad() {
if (typeof this.sx == 'string') {
this.sx = JSON.parse(this.sx) || {};
}
setCSSProps(this.host, Object.assign({}, this.sx));
}


render() {
return (
<Host
Expand All @@ -38,5 +36,4 @@ export class CbpTabPanel {
</Host>
);
}

}
2 changes: 1 addition & 1 deletion packages/web-components/src/components/cbp-tab/cbp-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class CbpTab {
/** Specifies whether this is the selected tab. Only one tab per tabset should be marked as selected.*/
@Prop({ reflect: true }) selected: boolean;

/** An optional color variant. */
@Prop({ reflect: true }) color: 'danger';

/** For tabs without a visible text label (e.g., icon tabs) or a label that is insufficiently unique/descriptive, you may provide accessibility text, which is rendered as an `aria-label` on the tab control (button element). */
Expand Down Expand Up @@ -78,5 +79,4 @@ export class CbpTab {
</Host>
);
}

}
4 changes: 2 additions & 2 deletions packages/web-components/src/components/cbp-tabs/cbp-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class CbpTabs {
setActiveTab(activatedTab) {
this.tabs.forEach((tab: HTMLCbpTabElement, index) => {
let button = tab.querySelector('button');
let panelid = button.getAttribute('aria-controls');
let panelid = tab.name;
let panel: HTMLCbpTabPanelElement = document.querySelector(`#${panelid}`);

if (!panel) {
Expand All @@ -53,7 +53,7 @@ export class CbpTabs {
tab.selected = true;
this.selectedIndex = this.focusIndex = index;
panel.selected = true;
button.scrollIntoView({ behavior: "smooth", inline: 'start' });
button?.scrollIntoView({ behavior: "smooth", inline: 'start' }); // Do nothing if the button hasn't been fully rendered yet - this is desired behavior on initial load.
} else {
tab.selected = false;
panel.selected = false;
Expand Down

0 comments on commit c02218f

Please sign in to comment.