kkinder / puepy

Python+Webassembly Frontend Framework via PyScript
https://puepy.dev
Apache License 2.0
193 stars 8 forks source link

PuePy should also set checked, style etc for WebComponents #33

Closed kkinder closed 1 month ago

kkinder commented 1 month ago

The code in core.py is designed to directly set checked and value as attributes on the value, not via DOM setAttribute. That's how it works with normal HTML elements:

        if self.bind and self.origin:
            if _element_input_type(element) == "checkbox":
                if is_server_side and self.origin.state[self.bind]:
                    element.setAttribute("checked", self.origin.state[self.bind])
                else:
                    element.checked = bool(self.origin.state[self.bind])
            else:
                if is_server_side:
                    element.setAttribute("value", self.origin.state[self.bind])
                else:
                    element.value = self.origin.state[self.bind]

However, I'm finding this does result in some bug with webcomponents that expect both to be set. So we should set both the .checked value and the .value itself, which shouldn't cause any issues.