pull/15844/head
Rich Harris 3 months ago
commit 2460370271

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: account for mounting when `select_option` in `attribute_effect`

@ -491,7 +491,7 @@ export function attribute_effect(
var current = set_attributes(element, prev, next, css_hash, skip_warning);
if (inited && is_select && 'value' in next) {
select_option(/** @type {HTMLSelectElement} */ (element), next.value, false);
select_option(/** @type {HTMLSelectElement} */ (element), next.value);
}
for (let symbol of Object.getOwnPropertySymbols(effects)) {
@ -516,7 +516,7 @@ export function attribute_effect(
var select = /** @type {HTMLSelectElement} */ (element);
effect(() => {
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value);
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value, true);
init_select(select);
});
}

@ -9,9 +9,9 @@ import * as w from '../../../warnings.js';
* @template V
* @param {HTMLSelectElement} select
* @param {V} value
* @param {boolean} [mounting]
* @param {boolean} mounting
*/
export function select_option(select, value, mounting) {
export function select_option(select, value, mounting = false) {
if (select.multiple) {
// If value is null or undefined, keep the selection as is
if (value == undefined) {

@ -0,0 +1,9 @@
import { ok, test } from '../../test';
export default test({
async test({ assert, target, instance }) {
const select = target.querySelector('select');
ok(select);
assert.equal(select.selectedIndex, 1);
}
});

@ -0,0 +1,8 @@
<script>
let others = {onclick: ()=> {}}
</script>
<select {...others}>
<option>o1</option>
<option selected>o2</option>
</select>
Loading…
Cancel
Save