Skip to content

Commit a912210

Browse files
authored
Merge branch 'dev' into feature/css-documentation
2 parents f394a2a + 0b3980a commit a912210

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class UUIButtonElement extends FormControlMixin(
4949
css`
5050
:host {
5151
position: relative;
52-
display: inline-block;
52+
display: inline-flex;
5353
margin-left: calc(var(--uui-button-merge-border-left, 0) * -1px);
5454
--uui-button-padding-left-factor: 3;
5555
--uui-button-padding-right-factor: 3;

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ export class UUISelectElement extends FormControlMixin(LitElement) {
158158
@state()
159159
private _disabledGroups: string[] = [];
160160

161+
private _values: string[] = [];
162+
161163
@query('#native')
162164
protected _input!: HTMLSelectElement;
163165

@@ -210,7 +212,18 @@ export class UUISelectElement extends FormControlMixin(LitElement) {
210212
}
211213

212214
willUpdate(changedProperties: Map<string | number | symbol, unknown>) {
213-
if (changedProperties.has('options')) this._extractGroups();
215+
if (changedProperties.has('options')) {
216+
this._extractGroups();
217+
this._values = this.options.map(option => option.value);
218+
const selected = this.options.find(option => option.selected);
219+
this.value = selected ? selected.value : '';
220+
}
221+
222+
if (changedProperties.has('value')) {
223+
this.value = this._values.includes(this.value as string)
224+
? this.value
225+
: '';
226+
}
214227
if (changedProperties.has('disabledGroups')) this._createDisabledGroups();
215228
}
216229

@@ -274,7 +287,8 @@ export class UUISelectElement extends FormControlMixin(LitElement) {
274287
aria-label=${this.label}
275288
@change=${this.setValue}
276289
?disabled=${this.disabled}
277-
.name=${this.name}>
290+
.name=${this.name}
291+
.value=${this.value as string}>
278292
<option disabled selected value="" hidden>${this.placeholder}</option>
279293
${this._renderGrouped()}
280294
${this.options

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

Lines changed: 13 additions & 7 deletions
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' },
6+
{ name: 'Carrot', value: 'orange', selected: true },
77
{ name: 'Cucumber', value: 'green' },
88
{ name: 'Aubergine', value: 'purple' },
99
{ name: 'Blueberry', value: 'Blue' },
@@ -64,11 +64,7 @@ describe('UUISelect in Form', () => {
6464
beforeEach(async () => {
6565
formElement = await fixture(
6666
html` <form>
67-
<uui-select
68-
label="foo"
69-
name="bar"
70-
.options=${options}
71-
value=${options[0].value}></uui-select>
67+
<uui-select label="foo" name="bar" .options=${options}></uui-select>
7268
</form>`
7369
);
7470
element = formElement.querySelector('uui-select') as any;
@@ -79,6 +75,14 @@ describe('UUISelect in Form', () => {
7975
expect(element.value).to.be.equal('orange');
8076
});
8177

78+
it('if value is set to a string that is not in the options array the value is empty string', async () => {
79+
element.value = 'something silly';
80+
await elementUpdated(element);
81+
const formData = new FormData(formElement);
82+
expect(element.value).to.be.equal('');
83+
expect(formData.get('bar')).to.be.equal('');
84+
});
85+
8286
it('form output', () => {
8387
const formData = new FormData(formElement);
8488
expect(formData.get('bar')).to.be.equal('orange');
@@ -117,7 +121,9 @@ describe('UUISelect in Form', () => {
117121
await elementUpdated(element);
118122
});
119123

120-
it('sets element to invalid when value is empty', () => {
124+
it('sets element to invalid when value is empty', async () => {
125+
element.value = '';
126+
await elementUpdated(element);
121127
expect(element.checkValidity()).to.be.false;
122128
});
123129

0 commit comments

Comments
 (0)