vscode-elements / elements

Web component library for developing Visual Studio Code extensions
https://vscode-elements.github.io
MIT License
156 stars 28 forks source link

React wrapper elements don't trigger change event #203

Closed neko-para closed 1 month ago

neko-para commented 1 month ago

Currently, neither of VscodeSingleSelect nor VscodeRadio call onChange. Manually addEventListener do help according to comment, but as that issue has been closed and the react wrapper released, doesn't it solved? Or possibly because change event is kind of native events and have some special logic? But VscodeButton does trigger click event.

neko-para commented 1 month ago

addEventListener example, which works.

const selEl = useRef<VscodeSingleSelectType | null>(null)

useEffect(() => {
    if (selEl.current) {
        const ls = (e: Event) => {
            console.log(e)
        }
        selEl.current.addEventListener('change', ls)

        return () => {
            selEl.current?.removeEventListener('change', ls)
        }
    }
}, [])

///

<VscodeSingleSelect
    ref={selEl}
>

onChange example, which doesn't work.

function onChangeTarget(event: FormEvent<VscodeSingleSelectType>) {
}

///

<VscodeSingleSelect
    onChange={onChangeTarget}
>
bendera commented 1 month ago

Fixed https://github.com/vscode-elements/react-elements/releases/tag/v0.5.0