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

Abnormal behavior under the input box. #237

Open
iuroc opened this issue Jan 13, 2024 · 4 comments
Open

Abnormal behavior under the input box. #237

iuroc opened this issue Jan 13, 2024 · 4 comments

Comments

@iuroc
Copy link

iuroc commented Jan 13, 2024

Using VanJS to create an input element with type number below, setting its value to a state, and then updating the value of this state in the oninput event of the element. When the input value in the element is 1.x, the cursor stays after x. However, when the delete key is pressed at this point, under normal circumstances, the cursor should move from after x to after ., and then x should be deleted. However, in the VanJS example below, after x is deleted, the input's value becomes 1, and the cursor moves in front of 1. This is obviously incorrect. Is this related to how VanJS updates the DOM content?

import van from 'vanjs-core'

const { div, input } = van.tags

const App = () => {

    const value = van.state('1.0')
    return div(
        input({
            type: 'number', value, oninput(event: KeyboardEvent) {
                value.val = (event.target as HTMLInputElement).value
            }
        })
    )
}

van.add(document.body, App())
@Tao-VanJS
Copy link
Member

This is due to the behavior of number-typed <input> element. When you delete x, event.target.value equals 1, not 1., as only numbers are allowed in the input box.

@iuroc
Copy link
Author

iuroc commented Jan 14, 2024

No, by x I mean any arbitrary number, and the issue will still persist in this case.

@iuroc
Copy link
Author

iuroc commented Jan 14, 2024

Please watch the video demonstration below.

QQ2024114-144317.video-converter.com.mp4

@Tao-VanJS
Copy link
Member

Yeah, I understand x means a number. My point is: event.target.value equals 1 for the input event that is triggered when you delete the number after the decimal point. This is the behavior of the DOM element.

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

2 participants