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

text field loosing state on render #579

Open
perguth opened this issue Oct 13, 2017 · 4 comments
Open

text field loosing state on render #579

perguth opened this issue Oct 13, 2017 · 4 comments

Comments

@perguth
Copy link
Contributor

perguth commented Oct 13, 2017

Expected behavior

Input fields should retain their state (and possibly focus as well as cursor position) regardless of emitter.emit('render')

Actual behavior

Text input fields loose their state/value on rendering.

Steps to reproduce behavior

Minimally adjusted code from the README shows the described behaviour: http://requirebin.com/?gist=829488013f4333ed528825df65c6a406

@simonwjackson
Copy link

@perguth Did you ever find a solution to this? I'm running into the same issue.

@perguth
Copy link
Contributor Author

perguth commented Nov 21, 2017

Yes, thanks to the friendly folks 👬 in #choo on freenode. I wrapped the input element in a Nanocomponent like so:

let Input = class Component extends Nanocomponent {
  constructor () {
    super()
    this.state = {}
  }
  createElement (state) {
    this.state = state
    return html`
      <input onkeypress=${state.onkeypress} onfocus=${state.onfocus} onblur=${state.onblur}
      class=form-control type=text placeholder='name or mac address' data-toggle=dropdown>
    `
  }
  update () {}
}
let input = new Input()

(source) and included it like so:

${input.render({onkeypress: search, onfocus: showSuggestions, onblur: hideSuggestions})}

(source).

Nonetheless this behaviour was considered a 🪲bug.

@bates64
Copy link
Contributor

bates64 commented Dec 21, 2017

Is this a bug in nanomorph? I guess it just needs to not consider el.value a modified property.

@jfr3000
Copy link

jfr3000 commented Oct 29, 2018

is there any update on this?

my workaround in the meantime is to attach an isSameNode handler to the input field as documented here: https://github.com/choojs/choo#caching-dom-elements

const inputField = input({type: "text"})
inputField.isSameNode = (target) => {
  return (target && target.nodeName && target.nodeName === 'INPUT')
}

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

4 participants