-
Notifications
You must be signed in to change notification settings - Fork 80
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
Slot-based horizontal alignment in HorizontalLayout #5038
Comments
In practice, the index management probably means something like:
|
Open questions:
|
I guess that would make more sense since with
Whereas with using |
I guess this depends on how we want to handle |
mmh, I honestly don't think we need to consider text nodes in layouts – first of all it's extremely rare, and secondly we can simply document that this feature doesn't work with text nodes at all. As for the behavior, I've tweaked my codepen behavior proto a bit and I think this would make a lot of sense: https://codepen.io/rsmeds/pen/dygYExp |
(Frustrating that we don't yet have |
We would need to make sure Speaking of public void setHorizontalComponentPlacement(Placement placement, Component... components) { This would be aligned with |
Yes, I do think it makes sense to have such a setter (which means also having an enum for the placement), however: there also needs to be an add(Placement placement, Component... components) And I wish we could find a better term than placement, but I have no idea what that would be. |
I wonder if and how this should work responsively. For example when using the Unwrapped Last element wrapped Last two elements wrapped All of those look off. I would probably would want to wrap each group below each other first, in which case I have to add containers anyway, plus figure out some CSS to apply the wrapping at some breakpoint. |
Maybe an alternative to "placement" could be "slot" |
Here is my version, based on Rolf's prototype, which seems to handle wrapping in a slightly more expected way: https://codepen.io/vursen-the-selector/pen/NPKyZMz |
Reworked the prototype using pseudo elements acting as "spacers" to avoid overriding The only problem with this approach is that added pseudo-elements are affected by the gap when |
I suppose the gap-doubling could be compensated for with a negative margin the size of the gap? |
Hmm, here's a codepen poc with pseudo-elements, negative margins, and |
I've also tinkered with a model where start, center and end have their own wrappers, but the problem with that approach is that it prevents flex-grow from working on the items. |
Created two new branches with prototypes based on the above codepens:
IMO the main benefit of the pseudo elements approach is better since it doesn't interfere with user styles:
|
Created a draft PR using margins approach: vaadin/web-components#8515 Seems like some wrapping problems are inevitable:
UPD: probably could be solved by adding state attributes like |
Description
An intuitive model for horizontally aligning elements in a HorizontalLayout, based on separate slots for left, center and right aligned elements.
Example
This layout has content aligned to the start, center and end:
With the existing API, you need to either
justify-content:space-between
, ormargin-left
/right
toauto
on the correct elementsThe purpose of the proposed feature is to simplify layouting by eliminating the need for wrappers or manual managing of auto-margins.
Acceptance criteria
start
,center
,end
center
andend
.addToStart(Component...)
(equivalent to normaladd(Component...)
)addToCenter(Component...)
addToEnd(Component...)
start
->center
->end
order, so that index-based APIs(indexOf,
getComponentAtIndex),
work intuitivelyJustifyContentMode
doesn't work together withcenter
andend
slots. This needs to be mentioned in the javadoc.getComponentCount()
etc will return total component count regardless of alignment slots.slot
attribute on elementsExamples
To produce
produces the index order
S1,
S2,
C1,
C2,
E1,
E2
(note that the indexes are according to slot order rather than the order in which they were added)
(the effective DOM-order of the elements is defined by the order of the slots in shadow DOM, so it doesn't matter that they're not declaratively in that order)
The above will render as
[S1 S2 C1 C2 E1 E2]
hl.getIndexAt(3)
=>C2
(note that this is despite C2 being added before S1 and S2)hl.addComponentAtIndex(4, C3)
=>[S1 S2 C1 C2 C3 E1 E2]
General criteria
Security
The text was updated successfully, but these errors were encountered: