Skip to content

Commit b48dcf5

Browse files
committed
remove select in option in uui-select
1 parent 3ae601b commit b48dcf5

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

packages/uui-select/lib/uui-select.element.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ declare global {
1111
name: string;
1212
value: string;
1313
group?: string;
14-
selected?: boolean;
1514
disabled?: boolean;
1615
}
1716
}
@@ -87,7 +86,6 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
8786
name: string;
8887
value: string;
8988
group?: string;
90-
selected?: boolean;
9189
disabled?: boolean;
9290
}`
9391
*/
@@ -173,8 +171,6 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
173171
if (changedProperties.has('options')) {
174172
this._extractGroups();
175173
this._values = this.options.map(option => option.value);
176-
const selected = this.options.find(option => option.selected);
177-
this.value = selected ? selected.value : '';
178174
}
179175

180176
if (changedProperties.has('value')) {
@@ -200,13 +196,9 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
200196
private _renderOption(
201197
name: string,
202198
value: string,
203-
selected: boolean | undefined,
204199
disabled: boolean | undefined,
205200
) {
206-
return html`<option
207-
value="${value}"
208-
?selected=${selected}
209-
?disabled=${disabled}>
201+
return html`<option value="${value}" ?disabled=${disabled}>
210202
${name}
211203
</option>`;
212204
}
@@ -224,12 +216,7 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
224216
)}>
225217
${this.options.map(option =>
226218
option.group === group
227-
? this._renderOption(
228-
option.name,
229-
option.value,
230-
option.selected,
231-
option.disabled,
232-
)
219+
? this._renderOption(option.name, option.value, option.disabled)
233220
: '',
234221
)}
235222
</optgroup>`,
@@ -259,12 +246,7 @@ export class UUISelectElement extends UUIFormControlMixin(LitElement, '') {
259246
${this.options
260247
.filter(option => !option.group)
261248
.map(option =>
262-
this._renderOption(
263-
option.name,
264-
option.value,
265-
option.selected,
266-
option.disabled,
267-
),
249+
this._renderOption(option.name, option.value, option.disabled),
268250
)}
269251
</select>`;
270252
}

packages/uui-select/lib/uui-select.story.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ const options: Array<Option> = [
5252
{ name: 'Strawberry', value: 'red' },
5353
];
5454

55-
const preselectedOptions: Array<Option> = options.map(option => {
56-
if (option.name === 'Aubergine') return { ...option, selected: true };
57-
return option;
58-
});
55+
const preselectedValue: string = 'orange';
5956

6057
const groupedOptions: Array<Option> = options.map(option => {
6158
if (options.indexOf(option) <= 2) return { ...option, group: 'Vegetables' };
@@ -70,8 +67,9 @@ export const Default: Story = {
7067

7168
export const Preselected: Story = {
7269
args: {
73-
options: preselectedOptions,
70+
options: options,
7471
label: 'Preselected',
72+
value: preselectedValue,
7573
},
7674
parameters: {
7775
controls: { include: ['placeholder'] },
@@ -86,7 +84,7 @@ export const Preselected: Story = {
8684
const options: Array<Option> = [
8785
{ name: 'Carrot', value: 'orange' },
8886
{ name: 'Cucumber', value: 'green' },
89-
{ name: 'Aubergine', value: 'purple', selected: true },
87+
{ name: 'Aubergine', value: 'purple' },
9088
{ name: 'Blueberry', value: 'Blue' },
9189
{ name: 'Banana', value: 'yellow' },
9290
{ name: 'Strawberry', value: 'red' },
@@ -161,7 +159,8 @@ export const Readonly: Story = {
161159
args: {
162160
readonly: true,
163161
label: 'Label',
164-
options: preselectedOptions,
162+
options: options,
163+
value: preselectedValue,
165164
},
166165
parameters: {
167166
docs: {

packages/uui-select/lib/uui-select.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
33
import { UUISelectElement } from './uui-select.element';
44

55
const options: Array<Option> = [
6-
{ name: 'Carrot', value: 'orange', selected: true },
6+
{ name: 'Carrot', value: 'orange' },
77
{ name: 'Cucumber', value: 'green' },
88
{ name: 'Aubergine', value: 'purple' },
99
{ name: 'Blueberry', value: 'Blue' },

0 commit comments

Comments
 (0)