-
Notifications
You must be signed in to change notification settings - Fork 286
Add basic support for key events #773
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
Conversation
| return strToData(s); | ||
| } | ||
|
|
||
| pub fn textareaSetValue(textarea: *TextArea, value: []const u8) !void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note value has a defaultValue. So likely needs the same care as HtmlInputElement.Value.
It may be implemented correctly here, but it is not obvious to me.
I think it may be best to also implement defaultValue as they considered the same property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my testing, both TextArea and Input will return something like value orelse defaultValue if the value hasn't been set. So that's right.
However, they both only have defaultValue if defaultValue is explicitly set. Given this html:
<textarea id=ta>abc</textarea>Then this JS should return abc:
document.getElementById("ta").value;But it returns empty.
Only if we explicitly set defaultValue:
document.getElementById("ta").defaultValue = 'abc'Does everything work as expected.
In other words, I guess when we're parsing the page, we should be looking for any input/textarea and setting their defaultValue as needed since libdom doesn't do it for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, generally the logic is something like x orelse defaultX orelse initialX where initialX is the value as defined if not set upon construction, not to be confused with the afterInvalidX and then there are errorXs, which when set throw an error instead of using the afterInvalidX.
Other surprising behavior is that Element.setAttribute(element, 'value', 'abc') will set defaultValue, not value.
<textarea id=ta>abc</textarea> document.getElementById("ta").value;
That this does not work is surprising, but libDOM struggles a lot with these details.
I'm a fair way towards being able to implement HtmlElements without C in Zig such that we can have much easier control. Mainly I just need to work out which DOM events to send (deprecated for external usage, but we still use them internally). Tho I would need to look into why that abc is dropped in the first example.
Support CDP's Input.dispatchKeyEvent and DOM key events. Currently only keydown is supported and expects every key to be a displayable character. It turns out that manipulating the DOM via key events isn't great because the behavior really depends on the cursor. So, to do this more accurately, we'd have to introduce some concept of a cursor. Personally, I don't think we'll run into many pages that are purposefully using keyboard events. But driver (puppeteer/playwright) scripts might be another issue.
Submit form on "Enter" within text input. Convert "Enter" to "\n" in textarea.
Co-authored-by: Sjors <[email protected]>
cde4454 to
cf39bdc
Compare
Support CDP's Input.dispatchKeyEvent and DOM key events. Currently only keydown is supported and expects every key to be a displayable character.
It turns out that manipulating the DOM via key events isn't great because the behavior really depends on the cursor. So, to do this more accurately, we'd have to introduce some concept of a cursor.
Personally, I don't think we'll run into many pages that are purposefully using keyboard events. But driver (puppeteer/playwright) scripts might be another issue.