Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-points-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': patch
---

**select**: update value after option change
13 changes: 6 additions & 7 deletions packages/core/src/components/bal-select/bal-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
*/

connectedCallback() {
const debounceUpdateOptions = debounce(() => this.updateOptions(), 0)
const debounceUpdateOptions = debounce(() => this.updateOptions(), 10)

this.initialValue = this.value

Expand Down Expand Up @@ -477,7 +477,7 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
*/

private waitForOptionsAndThenUpdateRawValuesTimer?: NodeJS.Timeout
private async waitForOptionsAndThenUpdateRawValues() {
private waitForOptionsAndThenUpdateRawValues = async () => {
clearTimeout(this.waitForOptionsAndThenUpdateRawValuesTimer)
await deepReady(this.el)
const hasOptions = this.options.size > 0
Expand Down Expand Up @@ -519,6 +519,9 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
if (this.didInit && !this.remote) {
this.validateAfterBlur()
}
if (this.didInit && this.remote && this.options.size > 0) {
this.validateAfterBlur(true)
}
}

/**
Expand Down Expand Up @@ -914,7 +917,7 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
}

private handleKeyPress = async (ev: KeyboardEvent) => {
if (!this.isPopoverOpen && isSpaceKey(ev)) {
if (!this.isPopoverOpen) {
preventDefault(ev)
await this.open()
}
Expand All @@ -931,10 +934,6 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
if (!this.disabled && !this.readonly) {
this.inputValue = (ev.target as HTMLInputElement).value

if (!this.isPopoverOpen) {
this.popoverElement.present()
}

this.focusIndex = 0
this.updateFocus()
preventDefault(ev)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!doctype html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script type="module" src="/build/baloise-design-system.esm.js"></script>
<script nomodule src="/build/baloise-design-system.js"></script>
</head>
<body>
<bal-doc-app log-components="bal-select">
<main class="container">
<bal-heading>Basic</bal-heading>
<section>
<form action="https://www.w3schools.com/action_page.php" target="_blank">
<input type="text" name="firstName" autocomplete="given-name" />
<bal-select
id="bal-select-year"
name="street"
autocomplete="street-address"
placeholder="Try finding a year"
typeahead
remote
></bal-select>
<bal-select id="value" name="value" placeholder="Initial Value" typeahead remote></bal-select>
<bal-button element-type="submit" color="primary">Submit</bal-button>
</form>
<script>
const selectEl = document.getElementById('bal-select-year')
const valueEl = document.getElementById('value')

selectEl.addEventListener('balInput', event => {
console.log('balInput', event.detail)
selectEl.appendChild(createSelectOption('Oberer Brühlweg 17'))
selectEl.appendChild(createSelectOption('Hauptstrasse 5'))
selectEl.appendChild(createSelectOption('Bahnhofstrasse 10'))
selectEl.appendChild(createSelectOption('Im Hinterstück 9'))
selectEl.appendChild(createSelectOption('Gartenweg 3'))
})

function createSelectOption(value) {
const el = document.createElement('bal-select-option')
el.value = `v${value}`
el.label = value
el.innerHTML = value
return el
}

setTimeout(() => {
valueEl.value = 'vHauptstrasse 5'
console.log('----------------------------')
}, 1000)

setTimeout(() => {
valueEl.appendChild(createSelectOption('Oberer Brühlweg 17'))
valueEl.appendChild(createSelectOption('Hauptstrasse 5'))
valueEl.appendChild(createSelectOption('Bahnhofstrasse 10'))
valueEl.appendChild(createSelectOption('Im Hinterstück 9'))
valueEl.appendChild(createSelectOption('Gartenweg 3'))
console.log('----------------------------')
}, 2000)
</script>
</section>
</main>
</bal-doc-app>
</body>
</html>
Loading