Skip to content

Commit 1832082

Browse files
authored
Merge pull request #2105 from Licen-it/master
fix(ContentSwitcher): correctly displaying all switcher options (and update utils-position version)
2 parents 8f83ebc + afe6773 commit 1832082

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/content-switcher/content-switcher-option.directive.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import {
44
Input,
55
HostListener,
66
Output,
7-
EventEmitter
7+
EventEmitter,
8+
ElementRef,
9+
OnInit,
10+
Renderer2
811
} from "@angular/core";
912

1013
@Directive({
1114
selector: "[ibmContentOption]"
1215
})
13-
export class ContentSwitcherOption {
16+
export class ContentSwitcherOption implements OnInit {
1417
/**
1518
* Used to activate the option. Only one option may be `active` at a time
1619
*/
@@ -49,6 +52,8 @@ export class ContentSwitcherOption {
4952

5053
protected _active = false;
5154

55+
constructor(private renderer: Renderer2, private hostElement: ElementRef) {}
56+
5257
@HostListener("click", ["$event"])
5358
hostClick(event: MouseEvent) {
5459
this.onClick.emit(event);
@@ -66,4 +71,21 @@ export class ContentSwitcherOption {
6671
this.active = true;
6772
this.selected.emit(true);
6873
}
74+
75+
/*
76+
* encapsulating the content in a span with bx--content-switcher__label class
77+
* to mimic what is done in the react version
78+
*/
79+
ngOnInit(): void {
80+
const hostNativeElement = (this.hostElement.nativeElement as HTMLElement);
81+
const spanWrapper = this.renderer.createElement("span");
82+
this.renderer.addClass(spanWrapper, "bx--content-switcher__label");
83+
const hostChildren: ChildNode[] = [];
84+
hostNativeElement.childNodes.forEach(node => hostChildren.push(node));
85+
hostChildren.forEach(node => {
86+
this.renderer.removeChild(hostNativeElement, node);
87+
this.renderer.appendChild(spanWrapper, node);
88+
});
89+
this.renderer.appendChild(hostNativeElement, spanWrapper);
90+
}
6991
}

src/content-switcher/content-switcher.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ import { isFocusInLastItem, isFocusInFirstItem } from "carbon-components-angular
3636
class="bx--content-switcher"
3737
[class.bx--content-switcher--light]="theme === 'light'"
3838
role="tablist">
39-
<span class="bx--content-switcher__label">
40-
<ng-content></ng-content>
41-
</span>
39+
<ng-content></ng-content>
4240
</div>
4341
`
4442
})

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@carbon/icon-helpers": "10.9.0",
2020
"@carbon/icons": "10.20.0",
2121
"@carbon/telemetry": "0.0.0-alpha.6",
22-
"@carbon/utils-position": "1.1.3",
22+
"@carbon/utils-position": "1.1.4",
2323
"flatpickr": "4.6.1"
2424
}
2525
}

0 commit comments

Comments
 (0)