-
Notifications
You must be signed in to change notification settings - Fork 88
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
Custom item template support #165
Comments
@jouni is this task still in the backlog? body > #overlay::shadow .item {
white-space: normal;
}
body > #overlay::shadow .item[selected] {
color: var(--main-text-color);
background: var(--combo-box-selected-item-background);
} |
@web-padawan, thanks for asking! This feature is still on very high priority, but we’re a bit hesitant in working on it just yet, as we’re waiting for the Polymer team to finalise their work on new overlay elements, so that we can be compatible with that. The biggest problem at the moment is how to make CSS work so that it is still scoped somehow, while the overlay element resides outside the shadow DOM boundary of the owning element, and still keep the developer experience somewhat consistent with regular element styling. The situation should clarify during the next months. |
An idea of using CSS style modules for styling the items came to our mind. For example: <dom-module id="my-item-styles">
<template>
<style>
div {
color: red;
}
</style>
</template>
</dom-module>
<div>Global scope. This should not be red.</div>
<vaadin-combo-box items-style-module="my-item-styles" items="[1, 2, 3]">
<template>
<div>Item scope. This should be red.</div>
</template>
</vaadin-combo-box> Appending the style modules programmatically will not be simple, but still possible. After some prototyping with @Saulis, we’ve concluded, that this has to be implemented differently, depending on the Polymer version and DOM mode. In general, with shadow DOM, simply appending a
See also: Polymer/polymer#3123 |
One question: it would still be possible to style the item templates using global CSS, right? So it would not be mandatory to write a DOM module for them? I would think that’s a more common use case, and the developer/designer just makes sure themselves to scope the styles properly (with BEM style selectors or something similar). |
Decided to split out the custom styling into its own ticket. In the scope of this ticket, we'll just handle the stamping of the custom item template and placing the item instance. |
vaadin/vaadin-combo-box#165 Flow-component: vaadin-combo-box
vaadin/vaadin-combo-box#165 Flow-component: vaadin-combo-box
Split from #96, where this was already researched.
Research report
Exposing items template is one step beyond the scope of this task. Despite that, it was also prototyped to get the idea of its complexity level.
The prototype branch contains a draft but working implementation: https://github.com/vaadin/vaadin-combo-box/tree/proto/custom-item-template
Exposing an item template is a complex task as well (roughly at the sample level, I’d say). While possible per se, still it requires to introduce a separate
vaadin-combo-box-item
element and expose theiron-list
in the light DOM of the overlay. Deep explanation of the problems below.iron-list
item template with the template provided in the combo-box light DOM..item
node defined inside the overlay, assigning model and state attributes (likeid
with index,selected
,focused
, ARIArole
andaria-selected
) and basic styles to it..item
wrapper.<template>
nodes as well, extracting bindings into the annotations. After this parsing at the register time, it’s impossible to modify the contents of the item template.<template preserve-content>
(undocumented Polymer feature) attribute to theiron-list
item template. This makes it possible to modify the item template, but at the same time effectively prevents the.item
bindings to the overlay methods from being parsed and working. Hence thefocused
indication and ARIA attributes don’t work.div.item
into a separatevaadin-combo-box-item
element, that would support custom template in thetemplate
property. This is currently implemented in the prototype branch.templatize()
it with either a given template or a default item template, stamp a template instance and append it to the light DOM. The changes to the bounditem
model should be updated on the stamped template instance manually.iron-list
exposes the item nodes in the light DOM. But still the overlay also needs to expose theiron-list
in the light DOM, in order to be targetable with global CSS.Related issues
The text was updated successfully, but these errors were encountered: