Preact: IE11 throws on input type="date"

Created on 11 Nov 2019  路  7Comments  路  Source: preactjs/preact

Reported via slack:

charlie 9:56 PM
going for a good head scratcher.. If I I have IE11 just breaks with a "Error: Invalid argument." error (changing the type to text brings it back to life). Fine in 8. While the type isn't supported, I'd expect IE to just gracefully degrade back to a text input.

Had a quick look into it and IE 11 throws when you try to use the setter directly with a value it doesn't support.

// Throws
input.type = "date";

// Works
input.setAttribute("type", "date");
beginner-friendly bug

Most helpful comment

Yes but when called directly in type="date" then IE will throw, when using setAttribute it will use the fallback instead of crash

All 7 comments

Hi there. I would like to help in this issue. Forgive me for being noob. What is this issue ?

The issue is that IE 11 throws an exception where it should not. If an input type is not supported it should automatically fall back to type text per spec. That's what IE 11 does with input.setAttribute() but not with input.type. So we need to make sure that we're calling setAttribute in our code.

Awesome thanks @marvinhagemeister

@marvinhagemeister I don't think input type "date" is supported in IE 11. It seems to fallback to a text input type "text" since IE 11 does not recognize "date" (in plain html file). https://stackoverflow.com/a/54846005/2445295 so we could do the same and fallback to input type "text" in IE 11 and show user appropriate warning in development mode.

Yes but when called directly in type="date" then IE will throw, when using setAttribute it will use the fallback instead of crash

You can find how we handle o ther of these edge cases in diffProps

This should be fixed by the next release thanks to #2147

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skaraman picture skaraman  路  3Comments

SabirAmeen picture SabirAmeen  路  3Comments

philipwalton picture philipwalton  路  3Comments

nopantsmonkey picture nopantsmonkey  路  3Comments

jasongerbes picture jasongerbes  路  3Comments