Skip to content

Commit 8f4af0f

Browse files
authored
Merge pull request #3081 from carbon-design-system/m-to-next
Merging branch master into next
2 parents 3a6d6aa + 91f6c83 commit 8f4af0f

File tree

6 files changed

+68
-18
lines changed

6 files changed

+68
-18
lines changed

src/combobox/combobox.component.spec.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ import { PlaceholderModule } from "./../placeholder/index";
2121
placeholder="placeholder"
2222
label="label"
2323
[items]="items"
24-
[(ngModel)]="model">
24+
[(ngModel)]="model"
25+
[type]="type"
26+
[itemValueKey]="itemValueKey">
2527
<cds-dropdown-list></cds-dropdown-list>
2628
</cds-combo-box>`
2729
})
2830
class ComboboxTest {
2931
items = [
30-
{content: "one", selected: false},
31-
{content: "two", selected: false},
32-
{content: "three", selected: false}
32+
{id: "1", content: "one", selected: false},
33+
{id: "2", content: "two", selected: false},
34+
{id: "3", content: "three", selected: false}
3335
];
36+
type = "single";
37+
itemValueKey = undefined;
3438
model: ListItem;
3539
}
3640

@@ -76,6 +80,7 @@ describe("Combo box", () => {
7680
fixture.detectChanges();
7781

7882
expect(element.nativeElement.querySelector("input").value).toBe("one");
83+
expect(wrapper.model.id).toBe("1");
7984
expect(wrapper.model.content).toBe("one");
8085
expect(wrapper.model.selected).toBe(true);
8186

@@ -173,9 +178,9 @@ describe("Combo box", () => {
173178
textInput.dispatchEvent(new Event("input"));
174179

175180
wrapper.items = [
176-
{content: "four", selected: false},
177-
{content: "five", selected: false},
178-
{content: "six", selected: false}
181+
{id: "4", content: "four", selected: false},
182+
{id: "5", content: "five", selected: false},
183+
{id: "6", content: "six", selected: false}
179184
];
180185

181186
fixture.detectChanges();
@@ -184,4 +189,24 @@ describe("Combo box", () => {
184189

185190
expect(itemEls.length).toEqual(2);
186191
});
192+
193+
it("should update model by itemValueKey when specified", () => {
194+
fixture = TestBed.createComponent(ComboboxTest);
195+
wrapper = fixture.componentInstance;
196+
wrapper.type = "multi";
197+
wrapper.itemValueKey = "id";
198+
fixture.detectChanges();
199+
200+
element = fixture.debugElement.query(By.css("cds-combo-box"));
201+
202+
const dropdownToggle = element.nativeElement.querySelector(".cds--list-box__field");
203+
dropdownToggle.click();
204+
fixture.detectChanges();
205+
206+
const dropdownOption = element.nativeElement.querySelector(".cds--list-box__menu-item");
207+
dropdownOption.click();
208+
fixture.detectChanges();
209+
210+
expect(wrapper.model).toEqual(["1"]);
211+
});
187212
});

src/combobox/combobox.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
638638
// clone the items and update their state based on the received value array
639639
// this way we don't lose any additional metadata that may be passed in via the `items` Input
640640
let newValues = [];
641-
for (const v of value) {
641+
for (const v of value ?? []) {
642642
for (const item of this.view.getListItems()) {
643643
if (item[this.itemValueKey] === v) {
644644
newValues.push(Object.assign({}, item, { selected: true }));
@@ -696,12 +696,12 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
696696
const selected = this.view.getSelected();
697697

698698
// in case there are disabled items they should be mapped according to itemValueKey
699-
if (this.itemValueKey && selected) {
700-
const values = selected.map((item) => item[this.itemValueKey]);
701-
this.propagateChangeCallback(values);
702-
} else {
703-
this.propagateChangeCallback(selected);
704-
}
699+
if (this.itemValueKey && selected) {
700+
const values = selected.map((item) => item[this.itemValueKey]);
701+
this.propagateChangeCallback(values);
702+
} else {
703+
this.propagateChangeCallback(selected);
704+
}
705705

706706
this.selected.emit(selected as any);
707707
this.clear.emit(event);

src/datepicker/datepicker.stories.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const RangeTemplate = (args) => ({
132132
[rangeInvalid]="invalid"
133133
[rangeInvalidText]="invalidText"
134134
[dateFormat]="dateFormat"
135+
[flatpickrOptions]="flatpickrOptions"
135136
[value]="value"
136137
(valueChange)="valueChange($event)"
137138
[helperText]="helperText">
@@ -154,6 +155,7 @@ const RangeTemplate = (args) => ({
154155
[rangeWarn]="warn"
155156
[rangeWarnText]="warnText"
156157
[dateFormat]="dateFormat"
158+
[flatpickrOptions]="flatpickrOptions"
157159
(valueChange)="valueChange($event)"
158160
[helperText]="helperText">
159161
</cds-date-picker>
@@ -162,8 +164,12 @@ const RangeTemplate = (args) => ({
162164
export const Range = RangeTemplate.bind({});
163165
Range.args = {
164166
dateFormat: "d/m/Y",
165-
value: ["01/02/24", "08/02/24"],
166-
language: "en"
167+
value: ["02/11/24", "08/11/24"],
168+
language: "en",
169+
flatpickrOptions: {
170+
minDate: new Date("11/01/24"),
171+
maxDate: new Date("11/30/24")
172+
}
167173
};
168174
Range.argTypes = {
169175
language: {

src/icon/icon.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export class IconDirective implements AfterViewInit, OnChanges {
8181
}
8282

8383
const svg = root.tagName.toUpperCase() !== "SVG" ? svgElement : root;
84-
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
84+
const xmlns = "http://www.w3.org/2000/svg";
85+
svg.setAttribute("xmlns", xmlns);
8586

8687
const attributes = getAttributes({
8788
width: icon.attrs.width,

src/pagination/pagination.component.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,22 @@ describe("Pagination", () => {
174174
fixture.detectChanges();
175175
expect(wrapper.pageOptions).toEqual(Array(1));
176176
});
177+
178+
it("should replace the select with a number input when the pagination threshold is reached", () => {
179+
const fixture = TestBed.createComponent(PaginationTest);
180+
const wrapper = fixture.componentInstance;
181+
fixture.detectChanges();
182+
element = fixture.debugElement.query(By.css("cds-pagination"));
183+
184+
element.componentInstance.pageSelectThreshold = 500;
185+
fixture.detectChanges();
186+
expect(element.nativeElement.querySelector(".cds--select__page-number input")).toBe(null);
187+
expect(element.nativeElement.querySelector(".cds--select__page-number select")).toBeDefined();
188+
189+
element.componentInstance.pageSelectThreshold = 2;
190+
fixture.detectChanges();
191+
expect(element.nativeElement.querySelector(".cds--select__page-number input")).toBeDefined();
192+
expect(element.nativeElement.querySelector(".cds--select__page-number select")).toBe(null);
193+
194+
});
177195
});

src/pagination/pagination.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export interface PaginationTranslations {
137137
<option *ngFor="let page of pageOptions; let i = index;" class="cds--select-option" [value]="i + 1">{{i + 1}}</option>
138138
</select>
139139
<svg
140-
*ngIf="pageOptions.length <= 1000"
140+
*ngIf="pageOptions.length <= pageSelectThreshold"
141141
cdsIcon="chevron--down"
142142
size="16"
143143
style="display: inherit;"

0 commit comments

Comments
 (0)