Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding select options always sets select value to last item #57

Open
timwis opened this issue Dec 21, 2016 · 2 comments
Open

Adding select options always sets select value to last item #57

timwis opened this issue Dec 21, 2016 · 2 comments

Comments

@timwis
Copy link
Contributor

timwis commented Dec 21, 2016

If you have an empty <select> box and then later add items to it, the "selection" (value) of the select box always seems to be set to the final item. I would expect it to be set to the first item, as it is when you first load a select box with items in it and no explicit value set.

In my case, I'd like to keep it focused on the option that says "Select..." until the user actually selects something.

Here's a small test case. I think requirebin's gatekeeper server is down so I can't post a demo.

const yo = require('yo-yo')

const View = (items) => yo`
  <select>
    ${items.length
      ? yo`<option value="">Select...</option>`
      : ''}
    ${items.map((item) => yo`
      <option>${item}</option>
    `)}
  </select>
`

const noItems = []
const viewA = View(noItems)

document.body.appendChild(viewA)

window.setTimeout(() => {
  const aFewItems = ['a', 'b', 'c']
  const viewB = View(aFewItems)
  yo.update(viewA, viewB)
}, 3000)

Any idea what's wrong?

@juliangruber
Copy link
Contributor

does this work?

? yo`<option value="" selected>Select...</option>`

@timwis
Copy link
Contributor Author

timwis commented Dec 21, 2016

That doesn't seem to have an effect :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants