Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New input placeholder behavior in Safari 10 - no longer hides on change via JavaScript

Safari 10.0 in macOS Sierra seems to have changed the way the placeholder in an input behaves when the input value is changed via JavaScript. It now also differs from what Chrome (53.0.2785.116) is doing.

Until now, when setting an input value via JavaScript the placeholder would disappear. After setting the value back to empty via JavaScript, the placeholder would reappear.

Now, setting the input value via JavaScript does not hide the placeholder, until the input gains focus afterwards (e.g. by being clicked on).

Check this JS Bin for a demo: https://jsbin.com/rogoludahu/edit?html,js,output

Is this the intended behavior? If so, is there a clever workaround for hiding/unhiding the placeholder after a change via JavaScript?

Edit: This has now been filed at rdar://28412751 for Safari 10 and the Safari Technology Preview.

like image 417
Joshua Avatar asked Sep 21 '16 19:09

Joshua


People also ask

What is placeholder shown in CSS?

The :placeholder-shown pseudo-class selects the input element itself when placeholder text exists in a form input. Think of it as a nice way to distinguish between inputs that are currently showing placeholder text versus those that are not.


2 Answers

I ran into this problem earlier today. As far as I've seen, there is no good solution. My hacky workaround was to call .focus() and then .blur() on the element as soon as the value was given to it.

like image 124
JustAProgrammer Avatar answered Sep 22 '22 00:09

JustAProgrammer


This has been resolved in Safari Technology Preview Release 37 (Safari 11.1, WebKit 12605.1.2) as well as in regular Safari Version 11.0.3 (WebKit 13604.5.6).

like image 22
Joshua Avatar answered Sep 24 '22 00:09

Joshua