-
Notifications
You must be signed in to change notification settings - Fork 707
[css-grid-2] resolving line names in subgrids #2564
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
Comments
Thanks for filing all these detailed issues, @MatsPalmgren! ISSUE 1: Agreed, clearly a bugfix change. ISSUE 2: Agreed, this is consistent with item f in https://www.w3.org/TR/2018/WD-css-grid-2-20180427/#subgrid-items ISSUE 3: I think in this case explicit names in the outer grid that are outside the subgrid’s bounds should not match. The only parent line names in scope are the ones where the parent and the subgrid share the line name. This was the intention of item c, “the subgridded lines automatically receive the line names specified on the parent grid” and is consistent with the idea of scoping the subgrid's line references per item b, “The grid-placement properties of the subgrid’s grid items are scoped to the lines covered by the subgrid.” (It's not clear from your examples whether this is what you meant, or you meant the opposite. As it happens, either choice gives the results you specified. ^_^ Here's a more explicit example:
Here, the parent grid's line 1, 3, and 5 are named "a". The subgrid spans from lines 1-4. If the parent grid's lines outside the subgrid's bounds are visible, then the item will anchor its grid-column-end to line 5, which is clamped to 4. Then it will seek startwards and find line 3 as the next "a" line, for a final position of 3 / 4. If they're not visible, it'll anchor its grid-column-end to line 3 (the last visible "a" line), then span to line 1, for a final position of 1 / 3. This is the correct/intended behavior.) ISSUE 4: This is an interesting case, I hadn't really thought about it. Named areas don't really "exist" in Grid; they're just a shorthand syntax for adding *-start and *-end line names to the grid. (Note that you can use If we resolve by simply ignoring the line names outside the subgrid’s spanning area, then the -start/-end lines outside the subgrid area would just get dropped. The item would then position against the subgrid's fake-implicit grid lines, and subsequently get clamped to the actual bounds of the subgrid, yielding the same behavior you propose. ISSUE 5: If we take the position that areas generate line names which are treated just like any other line names (the current Grid 1 specified behavior), then there's no order dependence (other than the order-dependence inherent in resolving named lines). Then there can be some confusing results if names conflict, but then, that's true for inheriting line names in general. ISSUE 6: Again, if areas just define lines to match against, and have no further independent existence, then there's no ambiguity here - the Note that if you'd said ISSUE 7: Agreed; this is already edited into the spec, I believe: https://drafts.csswg.org/css-grid-2/#subgrid-per-axis “Excess |
…late-areas) are passed through, but the infinite names of implicit grid lines (used to resolve placement against named lines that don't exist) are not. #2564
…ne numbers work more clearly. #2564
@MatsPalmgren OK, I edited in some clarifications to reflect the discussion above. Let me know if anything is still unclear or if you disagree with the spec on any point? Also flagging for additional review by the CSSWG. |
The Working Group just discussed The full IRC log of that discussion<dael> Topic: resolving line names in subgrids<dael> github: https://github.com//issues/2564 <dael> fantasai: Just a request for <dael> TabAtkins: For review from WG <dael> fantasai: The way we resolved these questions there was clarifications. Linenames are passed down and the rest of the behavior falls out from that. We could add additional logic to change behavior a little but we feltthis was straightforward. <dael> fantasai: Asking f or a look, don't need to discuss unless anyone has a comment or question <dael> astearns: Are the possible additions documented? <dael> fantasai: I think in the comments <dael> astearns: Sounds good <dael> astearns: Take this as a call to look at these changes. <dael> rachelandrew: Read through it and it seemed to make sense to me and be explainable <dael> astearns: Thanks <dael> astearns: Anything else? |
Right, they're not visible, so
The names in
Indeed, and in a non-subgrid world I would agree that they are entirely equivalent. However, in a subgrid world, a subgridded axis "shares" the tracks with its parent grid so it seems logical to me that the names in the parent <div style='display:grid; grid-template-areas: "a a a a a"'>
<div style="display:grid; grid:auto/subgrid; grid-column:2/span 3">
<x style="grid-column:a-start">x</x>
</div>
</div> I think the |
@MatsPalmgren I think I was misinterpreting the search direction, thought that Since there are a lot of issues here, and it seems like this one needs more discussion, I've refiled the template subsetting issue into #4411 We can continue discussion there. Let me know if everything else in this issue has been resolved to your satisfaction? |
I think ISSUE 5 and 6 hinges on how #4411 resolves the |
@MatsPalmgren #4411 has been resolved. Are we OK to close here? |
I figured it might be useful to provide some details on how the nested line name resolution works for subgrids in the prototype I implemented. Hopefully it can illuminate the issues and provide a starting point for a discussion on what the spec should say on the matter. (CAVEAT: bear in mind that for this prototype I intentionally implemented what required the least amount of work while still giving somewhat reasonable results. "Least amount of work" might be different for other UA vendors. I also haven't thought very deep about "does this make sense for authors" :-))
There are two ways to add local line names to a subgrid:
subgrid <line-name-list>?
syntax ingrid-template-rows/columns
,where
<line-name-list>
expands to:<line-name-list> = [ <line-names> | repeat([ <positive-integer> | auto-fill ], <line-names>) ]+
auto-fill
works similarly to how it works for tracks, except here we fill the extent of the grid rather than a target layout size.grid-template-areas
ISSUE 1: the first thing that needs to be addressed is how implicit lines in ancestor grids match line names. Grid 1 has this rule: "all implicit grid lines are assumed to have that name..." which doesn't work very well when looking up names from a descendant subgrid. For example:
The outer grid has 10 implicit tracks with implicit grid lines between them. So using that rule, line 2 in the outer grid would match
b
, which doesn't seem desirable. So the subgrid spec needs to explicitly override that rule so that the localb
line matches above.ISSUE 2: since subgrids don't have implicit tracks, and thus there are no implicit grid lines that would match line names that otherwise have no match, we need to define how those names are resolved.
Using the example above, how should a subgrid item with
grid-column: foo / span 4
be resolved? The way I handle it internally is to pretend that there are in fact implicit grid lines, and then simply clamp the result afterwords. This was the simplest to implement because it allowed me to re-use the existing line name resolution code as is for the most part. So first we resolvefoo
to 12, then clamp that to 11, then span 4 from there to 15, then clamp that to 11, then enforce a minimum span 1, to get the final result 10 / 11 (placing it in the last subgrid track). Forgrid-column: span bar 2 / foo 3
we resolve tofoo 3
to 14, then clamp that to 11, then search start-wards for two matchingbar
lines from there, which results in -1 (the second "implicit line" on the start side) which is then clamped to 1, so this item spans the entire subgrid (1 / 11).ISSUE 3: explicit line names in outer grids that are outside the bounds of the subgrid needs to be defined how/if they match.
I solved this case similarly to the above, so for example:
we first resolve
a 18
to 18 which is then clamped to 11, then we resolvespan a
start-wards from there, matching line 10. This however:resolves
a 8
to 18, which is clamped to 11, but since there are no matches fora
start-wards from 11 it matches the first "implicit" line on the start side, so the final result is 1 / 11.ISSUE 4: line name matching for
grid-template-areas
that are (partly) outside of the bounds of the subgrid needs to be definedThe way I solved this is to view the areas themselves as sliced by the subgrid and then generate implicit area names for that slice, for example:
Resolves to 1 / 6, because the subgrid sees a
a-start
line at its line 1 anda-end
at line 11. That is, the areas in ancestor grids that have an edge outside the subgrid generates its corresponding implicit area name at the subgrid edge instead. This matters because for example:Resolves to 2 / 3, because the
a-start
of the parent grid coincides with the explicita-start
at line 1 in the subgrid.Note that implicit area names are still generated for all grids though, so for example:
have
a-start
lines at line 1 (from the outermost subgrid), line 2, line 3 (from the innermost subgrid) and line 4 (from the root grid) soa-start 4
is resolved as 4 in this case.ISSUE 5: there is an order-dependent rule for resolving plain
<custom-ident>
which is ambiguous when the matching is nestedI solved it by recursing on all nested areas first, and only if none of them have a matching area name we treat it as
<custom-ident> 1
. So here for example,a
matches the explicita-start
line because there exists an area nameda
, so the result is 2 / 6.ISSUE 6: the spec needs to define where implicit area line names occurs when the relevant grid axes have opposite progression directions
For example:
I implemented this by matching all names as viewed from the subgrid's perspective, so the implicit
a-start
associated with thea
area occurs at the right side when resolving names within the subgrid (and vice versa for -end names). So the item above is placed at 8 / 9 (which is 3 / 4 in the outer grid). I think this makes sense if you view the areas as areas and the associated implicit line names occurs as viewed from the item we're resolving names for.ISSUE 7: local names within the subgrid itself may be outside the subgrid bounds - the spec needs to define how these are handled. For example:
resolves to 2 / 3, because searching from the end starts at the end of the grid (line 3), so the trailing
[a]
s are disregarded (just like names outside of the subgrid bounds in ancestors are). Ditto for:This also resolves to 2 / 3.
Other than that it follows how line name resolution in general works in Grid 1.
While the above may sound complex and thus hard to implement, it actually was fairly straight-forward. Pretty much all existing line name resolution code can be used intact. I only needed to splice in a recursion step in a couple of places, and change existing clamping code to clamp to the subgrid bounds instead of a min/max constant.
The text was updated successfully, but these errors were encountered: