flo
flo

Reputation: 11

how to best capture the value in an sl-input component from the shoelace library

I am reasonably new to the shoelace web component library. I am trying to implement a callback to validate an input.

The only way I have found to capture the value in the input is to use evt.path[0].value when handling the slInput event. Is that really the way to do it. I see no example for this on https://shoelace.style

below is a jsx example. Assume that the validate() function does some magic to the current input value.

render() {
    return <sl-input 
               type="text"
               onSlInput={(evt) => doSomethingWithValue(evt.path[0].value)}
           />
}

The above is working but a) .path is not a standard property of CustomEvent and b) what guarantee do I have that the value is always in path[0]?

edit: this works.

render() {
    return <sl-input 
               type="text"
               onSlInput={(evt) => doSomethingWithValue(evt.target.value)}
           />
}

Upvotes: 1

Views: 926

Answers (0)

Related Questions