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
Getting valueAsDate from input right after setting value #1302
Comments
I was able to reproduce and fix this locally, but I wasn't able to repro it in the test runner, so I couldn't add a test. If anyone is interested in preventing a regression, feel free to take a stab at it. The problem was that the input wasn't available for reading before the component renders, meaning you could set |
Isn't something like this enough for testing? it('should read valueAsDate after writing value', async () => {
const el = await fixture<SlInput>(html` <sl-input type="date"></sl-input> `);
el.value = '2023-04-14';
const date = el.valueAsDate;
expect(date).to.be.instanceOf(Date);
expect(date!.getFullYear()).to.equal(2023);
expect(date!.getMonth()).to.equal(3);
expect(date!.getDate()).to.equal(14);
}); Problem is that it's failing on Webkit for me. But then I tried to test the same thing with native input and it's failing too: it('should read valueAsDate after writing value on native input', async () => {
const el = await fixture<HTMLInputElement>(html` <input type="date"> `);
el.value = '2023-04-14';
const date = el.valueAsDate;
expect(date).to.be.instanceOf(Date);
expect(date!.getFullYear()).to.equal(2023);
expect(date!.getMonth()).to.equal(3);
expect(date!.getDate()).to.equal(14);
}); Btw the reason I'm using the const date = new Date();
nativeInput.valueAsDate = date;
console.log(date.getTime() === nativeInput.valueAsDate.getTime()); // output: false |
The behavior exhibited in the test runner, for whatever reason, was not the same as what I saw locally. Could be a timing/lifecycle issue. Didn't have time to dive in. |
Describe the bug
The
valueAsDate
ofsl-input[type=date]
is null right after I set thevalue
. This behavior is different from the nativeinput
element and is similar to this issue: #760Example:
To Reproduce
Steps to reproduce the behavior:
sl-input[type=date]
value
valueAsDate
Browser / OS
The text was updated successfully, but these errors were encountered: