ampproject / ampproject/worker-dom

HTMLSelectElement.value does not return the correct value before user's action

Open
#537 0 comments 0 reactions 1 assignee Claimed by @kristoferbaxter View on GitHub
hydration
Dominant language
TypeScript
Stars
3.3k
Forks
154
PR merge metrics
No merged PRs in 30d

Description

HTMLSelectEelement.value does not work as expected when its value is specified with "selected" attribute.

## Description

I would use the following HTML snippet as an example:

~~~html

Tokyo
Sapporo
Osaka
Fukuoka
Okinawa

~~~

This select element's value is "Okinawa", because selected attribute is specified in the corresponding option element. Same text is acquired when el in the following code refers the select element mentioned above, see [this code in JSBIN](https://jsbin.com/zenupigola/edit?html,js,output) for full details.

~~~javascript
const el = document.querySelector("select");
const value = el.value; // this value should be "Okinawa".
~~~

However, this code works different in worker-dom. "el.value" is evaluated as "Tokyo" , which is different behavior from what we expect.

This different behavior happens only before the select element's value is changed by users' action.

## Expected result

HTMLSelectElement.value returns the value associated with a option element specified as "selected" before any user's action.

## Actual result

HTMLSelectElement.value is resolved with the value of its first option element.

## Examined code

https://jsbin.com/zenupigola/edit?html,js,output

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.