Inspect HTML5 date picker shadow DOM

2020-07-02 07:16发布

I'm trying to inspect the shadow DOM for certain HTML5 controls, like the date picker for the input type="date" and the actual suggestion dropdown list for inputs bound to a datalist. Preferably in Chrome, but other browsers will do too.

I've found that by enabling the Shadow DOM setting in Chrome's inspector options allows me to inspect the shadow DOM for the actual input (which includes the ::-webkit-calendar-picker-indicator arrow to show the datepicker) but not the datepicker itself:

enter image description here

The same goes for the datalist. It appears as these controls are not part of the input, but I also can't find them anywhere else in the elements panel.

Is it possible to inspect such elements?

Small edit for clarification: I'm actually looking for which pseudo-classes apply to which controls. There's plenty of sites that list some of them, but I have yet to find a source that manages to list ::-webkit-calendar-picker-indicator for the datalist element, which does get applied. I'm looking for more of those sneaky bastards, and the best source for that of course is the horse's mouth.

2条回答
淡お忘
2楼-- · 2020-07-02 07:36

Looks like the actual picker is loaded in an entirely different layer (basically a different window without the titlebar). So I guess the answer is: no, you can't.

enter image description here

I agree it would be great to be able to customize it. And similar popups too. Mozilla in XUL has display:popup which is used by context menus, flyout and similar things. Would be definitely great being able to use that in userland content too.

查看更多
【Aperson】
3楼-- · 2020-07-02 07:53

The calendar popup of Google Chrome is not in Shadow DOM. It's in a separated page mapped to a popup window. See WebPagePopupImpl.cpp

And the popup content is written by HTML/JavaScript.

查看更多
登录 后发表回答