Skip to content

Commit 34332d9

Browse files
authored
Merge branch 'carbon-design-system:master' into master
2 parents 34d7582 + 7eb80c7 commit 34332d9

File tree

9 files changed

+163
-33
lines changed

9 files changed

+163
-33
lines changed

.github/workflows/check-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111

1212
runs-on: ubuntu-latest
1313

14-
# We use Node v16 for building since CCA@v5 is using Angular 14.
14+
# We use Node v18 for building since CCA@v5 is using Angular 14.
1515
strategy:
1616
matrix:
17-
node-version: [16.x]
17+
node-version: [18.x]
1818

1919
steps:
2020
- uses: actions/checkout@v3

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ jobs:
2727
- name: Checkout
2828
uses: actions/checkout@v3
2929

30-
# Set up node to use v16
30+
# Set up node to use v18
3131
- name: Setup Node
3232
uses: actions/setup-node@v3
3333
with:
34-
node-version: "16"
34+
node-version: "18"
3535
cache: "npm"
3636
cache-dependency-path: "package-lock.json"
3737

.storybook/manager-head.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
<meta name="twitter:image" content="https://angular.carbondesignsystem.com/carbon.jpg">
1111
<meta name="twitter:card" content="summary_large_image">
1212

13+
<footer>
14+
<dds-footer-container key="footer" disable-locale-button="true" size="micro" />
15+
</footer>
16+
17+
<script
18+
key="8"
19+
type="module"
20+
src="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v1/latest/footer.min.js">
21+
</script>
22+
1323
<!-- Storybook override -->
1424
<script>
1525
document.title = "Carbon Components Angular";
@@ -26,3 +36,20 @@
2636
send_page_view: false
2737
});
2838
</script>
39+
40+
<style>
41+
footer {
42+
position: absolute;
43+
bottom: 0;
44+
width: 100%;
45+
z-index: 9999;
46+
}
47+
48+
#root > div {
49+
/*
50+
* Subtracting the height of the footer to prevent
51+
* overlaying the footer ontop of content
52+
*/
53+
height: calc(100vh - 48px);
54+
}
55+
</style>

src/search/search.component.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,59 @@ describe("Search", () => {
8585
expect(component.value).toEqual("");
8686
});
8787

88+
it("should clear the input when the clear button is clicked on the expandable component", () => {
89+
component.expandable = true;
90+
component.value = "TextToClear";
91+
fixture.detectChanges();
92+
clearButtonElement = fixture.debugElement.query(By.css("button")).nativeElement;
93+
clearButtonElement.click();
94+
fixture.detectChanges();
95+
expect(component.value).toEqual("");
96+
});
97+
98+
it("should clear the input when the escape key is pressed", () => {
99+
clearButtonElement = fixture.debugElement.query(By.css("button")).nativeElement;
100+
component.value = "TextToClear";
101+
fixture.detectChanges();
102+
expect(clearButtonElement.className.includes("cds--search-close--hidden")).toEqual(false);
103+
component.keyDown(new KeyboardEvent("keydown", {
104+
"key": "Escape"
105+
}));
106+
fixture.detectChanges();
107+
expect(component.value).toBe("");
108+
expect(clearButtonElement.className.includes("cds--search-close--hidden")).toEqual(true);
109+
});
110+
111+
it("should clear the input and keep the expanded state open when the escape key is pressed", () => {
112+
component.expandable = true;
113+
component.active = true;
114+
containerElement = fixture.debugElement.query(By.css(".cds--search")).nativeElement;
115+
component.value = "TextToClear";
116+
fixture.detectChanges();
117+
expect(containerElement.className.includes("cds--search--expanded")).toEqual(true);
118+
component.keyDown(new KeyboardEvent("keydown", {
119+
"key": "Escape"
120+
}));
121+
fixture.detectChanges();
122+
expect(component.value).toBe("");
123+
expect(containerElement.className.includes("cds--search--expanded")).toEqual(true);
124+
});
125+
126+
it("should close the expandable search component when esc is pressed when content is empty", () => {
127+
component.expandable = true;
128+
component.active = true;
129+
containerElement = fixture.debugElement.query(By.css(".cds--search")).nativeElement;
130+
component.value = "";
131+
fixture.detectChanges();
132+
expect(containerElement.className.includes("cds--search--expanded")).toEqual(true);
133+
component.keyDown(new KeyboardEvent("keydown", {
134+
"key": "Escape"
135+
}));
136+
fixture.detectChanges();
137+
expect(component.active).toEqual(false);
138+
expect(containerElement.className.includes("cds--search--expanded")).toEqual(false);
139+
});
140+
88141
it("should have dark and light theme", () => {
89142
containerElement = fixture.debugElement.query(By.css(".cds--search")).nativeElement;
90143
component.theme = "dark";

src/search/search.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export class Search implements ControlValueAccessor {
3737
*/
3838
static searchCount = 0;
3939

40-
@HostBinding("class.cds--form-item") get containerClass() { return !(this.toolbar || this.expandable); }
40+
@HostBinding("class.cds--form-item") get containerClass() {
41+
return !(this.toolbar || this.expandable);
42+
}
4143

4244
/**
4345
* @deprecated since v5 - Use `cdsLayer` directive instead
@@ -221,11 +223,20 @@ export class Search implements ControlValueAccessor {
221223
keyDown(event: KeyboardEvent) {
222224
if (this.toolbar || this.expandable) {
223225
if (event.key === "Escape") {
224-
this.active = false;
226+
if (this.value === "") {
227+
this.active = false;
228+
this.open.emit(this.active);
229+
}
225230
} else if (event.key === "Enter") {
226231
this.openSearch();
227232
}
228233
}
234+
235+
if (event.key === "Escape") {
236+
if (this.value !== "") {
237+
this.clearSearch();
238+
}
239+
}
229240
}
230241

231242
@HostListener("focusout", ["$event"])

src/search/search.stories.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export default {
2020
autocomplete: "on"
2121
},
2222
argTypes: {
23+
expandable: {
24+
type: "boolean",
25+
defaultValue: false
26+
},
2327
size: {
2428
options: ["sm", "md", "lg"],
2529
control: "radio"
@@ -52,7 +56,8 @@ const Template = (args) => ({
5256
[disabled]="disabled"
5357
[size]="size"
5458
(valueChange)="valueChange($event)"
55-
(clear)="clear()">
59+
(clear)="clear()"
60+
[expandable]="expandable">
5661
</cds-search>
5762
`
5863
});

src/slider/slider.component.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,21 @@ describe("Slider", () => {
137137
fixture.detectChanges();
138138
expect(element.nativeElement.querySelector(".cds--slider--disabled")).toBeTruthy();
139139
});
140+
141+
it("should set the value of the right thumb if it's closer on click of the slider", () => {
142+
element.componentInstance.value = [0, 90];
143+
const slider = element.nativeElement.querySelector(".cds--slider");
144+
const track = element.nativeElement.querySelector(".cds--slider__track");
145+
const event = new MouseEvent("click", {clientX: track.getBoundingClientRect().right});
146+
slider.dispatchEvent(event);
147+
expect(element.componentInstance.value).toEqual([0, 100]);
148+
});
149+
150+
it("should set the value of the left thumb if it's closer on click of the slider", () => {
151+
element.componentInstance.value = [10, 100];
152+
const slider = element.nativeElement.querySelector(".cds--slider");
153+
const event = new MouseEvent("click", {clientX: 0});
154+
slider.dispatchEvent(event);
155+
expect(element.componentInstance.value).toEqual([0, 100]);
156+
});
140157
});

src/slider/slider.component.ts

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,38 +78,42 @@ import { EventService } from "carbon-components-angular/utils";
7878
</label>
7979
<div
8080
class="cds--slider"
81+
(click)="onClick($event)"
8182
[ngClass]="{'cds--slider--disabled': disabled}">
8283
<ng-container *ngIf="!isRange()">
83-
<div
84-
#thumbs
85-
role="slider"
86-
[id]="id"
87-
[attr.aria-labelledby]="labelId"
88-
class="cds--slider__thumb"
89-
[ngStyle]="{left: getFractionComplete(value) * 100 + '%'}"
90-
tabindex="0"
91-
(mousedown)="onMouseDown($event)"
92-
(keydown)="onKeyDown($event)">
84+
<div class="cds--slider__thumb-wrapper"
85+
[ngStyle]="{insetInlineStart: getFractionComplete(value) * 100 + '%'}">
86+
<div
87+
#thumbs
88+
role="slider"
89+
[id]="id"
90+
[attr.aria-labelledby]="labelId"
91+
class="cds--slider__thumb"
92+
tabindex="0"
93+
(mousedown)="onMouseDown($event)"
94+
(keydown)="onKeyDown($event)">
95+
</div>
9396
</div>
9497
</ng-container>
9598
<ng-container *ngIf="isRange()">
96-
<div
97-
#thumbs
98-
*ngFor="let thumb of value; let i = index; trackBy: trackThumbsBy"
99-
role="slider"
100-
[id]="id + (i > 0 ? '-' + i : '')"
101-
[attr.aria-labelledby]="labelId"
102-
class="cds--slider__thumb"
103-
[ngStyle]="{left: getFractionComplete(thumb) * 100 + '%'}"
104-
tabindex="0"
105-
(mousedown)="onMouseDown($event, i)"
106-
(keydown)="onKeyDown($event, i)">
99+
<div class="cds--slider__thumb-wrapper"
100+
[ngStyle]="{insetInlineStart: getFractionComplete(thumb) * 100 + '%'}"
101+
*ngFor="let thumb of value; let i = index; trackBy: trackThumbsBy">
102+
<div
103+
#thumbs
104+
role="slider"
105+
[id]="id + (i > 0 ? '-' + i : '')"
106+
[attr.aria-labelledby]="labelId"
107+
class="cds--slider__thumb"
108+
tabindex="0"
109+
(mousedown)="onMouseDown($event, i)"
110+
(keydown)="onKeyDown($event, i)">
111+
</div>
107112
</div>
108113
</ng-container>
109114
<div
110115
#track
111-
class="cds--slider__track"
112-
(click)="onClick($event)">
116+
class="cds--slider__track">
113117
</div>
114118
<div
115119
#filledTrack
@@ -446,11 +450,24 @@ export class Slider implements AfterViewInit, ControlValueAccessor {
446450
this.value = this.value;
447451
}
448452

449-
/** Handles clicks on the range track, and setting the value to it's "real" equivalent */
453+
/**
454+
* Handles clicks on the slider, and setting the value to it's "real" equivalent.
455+
* Will assign the value to the closest thumb if in range mode.
456+
* */
450457
onClick(event) {
451458
if (this.disabled) { return; }
452459
const trackLeft = this.track.nativeElement.getBoundingClientRect().left;
453-
this._value[0] = this.convertToValue(event.clientX - trackLeft);
460+
const trackValue = this.convertToValue(event.clientX - trackLeft);
461+
if (this.isRange()) {
462+
if (Math.abs(this._value[0] - trackValue) < Math.abs(this._value[1] - trackValue)) {
463+
this._value[0] = trackValue;
464+
} else {
465+
this._value[1] = trackValue;
466+
}
467+
} else {
468+
this._value[0] = trackValue;
469+
}
470+
454471
this.value = this.value;
455472
}
456473

src/table/cell/table-radio.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class TableRadio {
4040
get disabled(): boolean {
4141
return this.row ? !!(this.row as TableRow).disabled : false;
4242
}
43-
43+
4444
/**
4545
* Used to populate the row selection checkbox label with a useful value if set.
4646
*

0 commit comments

Comments
 (0)