Skip to content

Commit 9faef4e

Browse files
authored
Merge pull request #753 from exadel-inc/feature/select-multiple-values
feat(select-setting): ability to use more than one option value
2 parents 97fab0a + fff3c73 commit 9faef4e

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

site/src/examples/list.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
&.aqua {
2626
background-color: aqua;
2727
}
28+
29+
&.top {
30+
align-content: start;
31+
}
32+
&.center {
33+
align-content: center;
34+
}
35+
&.bottom {
36+
align-content: end;
37+
}
2838
}
2939

3040
&-circle {

site/views/examples/example/list.njk

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ title: Example with list of cards
106106
<uip-select-setting label="Card color:" target=".card-item" attribute="class" mode="append">
107107
<option value="red">Red</option>
108108
<option value="aqua">Aqua</option>
109-
<option value="green">Green</option>
109+
<option value="green green-clr">Green</option>
110+
</uip-select-setting>
111+
<uip-select-setting label="Text alignment:" target=".card-item" attribute="class" mode="append">
112+
<option value="top">Top</option>
113+
<option value="center">Center</option>
114+
<option value="bottom bottom-alignment">Bottom</option>
110115
</uip-select-setting>
111116
<uip-bool-setting label="Wrap items" attribute="wrap-items"></uip-bool-setting>
112117
</uip-settings>

src/plugins/settings/select-setting/select-setting.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ export class UIPSelectSetting extends UIPSetting {
8989
transformValue(value: string, attrValue: string | null): string | null {
9090
if (!attrValue) return value || null;
9191

92-
const attrTokens = this.settingOptions.reduce((tokens, option) =>
93-
TokenListUtils.remove(tokens, option), TokenListUtils.split(attrValue));
92+
const attrTokens = this.settingOptions.reduce((tokens, option) => {
93+
return TokenListUtils.split(option).reduce((token, optionItem) => TokenListUtils.remove(token, optionItem), tokens);
94+
}, TokenListUtils.split(attrValue));
9495
value && attrTokens.push(value);
9596

9697
return TokenListUtils.join(attrTokens);
@@ -125,15 +126,18 @@ export class UIPSelectSetting extends UIPSetting {
125126
/** Updates setting's value for {@link mode} = "append" */
126127
protected appendFrom(attrValues: (string | null)[]): void {
127128
// array of each attribute's value intersection with select options
128-
const valuesOptions = attrValues.map((val) => TokenListUtils.intersection(this.settingOptions, TokenListUtils.split(val)));
129+
const valuesOptions: string[] = this.settingOptions.filter((option) => {
130+
return TokenListUtils.split(option).length ===
131+
TokenListUtils.intersection(TokenListUtils.split(option), TokenListUtils.split(attrValues[0])).length;
132+
});
129133

130134
// make empty option active if no options intersections among attribute values
131135
if (this.settingOptions.includes('') && valuesOptions.every((inter) => !inter.length)) {
132136
return this.setValue('');
133137
}
134138

135139
// common options among all attribute values
136-
const commonOptions = TokenListUtils.intersection(...valuesOptions);
140+
const commonOptions = TokenListUtils.intersection(valuesOptions);
137141

138142
if (this.multiple || commonOptions.length) return this.setValue(TokenListUtils.join(commonOptions));
139143

@@ -146,7 +150,7 @@ export class UIPSelectSetting extends UIPSetting {
146150

147151
protected setValue(value: string): void {
148152
this.$$off(this._onChange);
149-
value.split(' ').forEach((opt) => this.$field.setSelected(opt, true));
153+
this.$field.setSelected(value, true);
150154
this.$$on(this._onChange);
151155
}
152156

0 commit comments

Comments
 (0)