Closed Bug 1359060 Opened 7 years ago Closed 7 years ago

[css-grid] fit-content unexpectedly reserves space for full clamp size in repeat()

Categories

(Core :: CSS Parsing and Computation, defect)

53 Branch
defect
Not set
minor

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: jonathan.snook, Assigned: MatsPalmgren_bugz)

References

Details

(Keywords: testcase)

Attachments

(2 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:53.0) Gecko/20100101 Firefox/53.0
Build ID: 20170413192749

Steps to reproduce:

Created grid layout using the following CSS:

```
#container {
  display: grid;
  grid-template-columns: repeat(auto-fit, fit-content(400px));
}
```

and the following HTML:
```
<div id="container">
  <div>Text A</div>
  <div>Text B</div>
  <div>Text C</div>
  <div>Text D</div>
</div>
```


Actual results:

Once the container is sized below 1600px, the grid items start flowing into subsequent rows.


Expected results:

Since each container's content is well below the clamp size of 400px, I expected all grid items to remain on the same row until the container was sized below total actual size of all items. (In my case, it was approximately 172px wide.)
Component: Untriaged → CSS Parsing and Computation
Product: Firefox → Core
Attached file Reporter's testcase
Assignee: nobody → mats
According to the CSS Grid spec, grid-template-columns: repeat(auto-fit, fit-content(400px))
is actually invalid, because <fixed-size> doesn't include fit-content():
https://drafts.csswg.org/css-grid/#typedef-auto-repeat
"repeat( [ auto-fill | auto-fit ] , [ <line-names>? <fixed-size> ]+ <line-names>? )"
https://drafts.csswg.org/css-grid/#typedef-fixed-size
"<fixed-size> = <fixed-breadth> | 
                minmax( <fixed-breadth> , <track-breadth> ) | 
                minmax( <inflexible-breadth> , <fixed-breadth> )"

It looks like Chrome (correctly) rejects this declaration as invalid.

IIRC, we implemented fit-content() (in bug 1281320) before the spec had a clear definition of
what sizes were allowed in an auto-repeat track size, so currently we interpret 400px as
a "definite track max size" and use that to calculate how many tracks to create.
This is probably not a very useful behavior, so I'll just fix this by rejecting
these values.  But feel free to open a spec issue at https://github.com/w3c/csswg-drafts/issues/new
if you want to argue for a spec change (please put [css-grid] first in the title).
Blocks: 1281320
Severity: normal → minor
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Keywords: testcase
OS: Unspecified → All
Hardware: Unspecified → All
Summary: fit-content unexpectedly reserves space for full clamp size in repeat() → [css-grid] fit-content unexpectedly reserves space for full clamp size in repeat()
Actually, after re-reading bug 1281320 and its patch, I think this is just a case that
we missed to reject somehow.  My bad.  Anyway, it's a pretty simple fix...
Comment on attachment 8862799 [details] [diff] [review]
fix

Review of attachment 8862799 [details] [diff] [review]:
-----------------------------------------------------------------

r=me

(Consider adding ", per spec" to the end of the commit message, in the spirit of bz's recent dev.platform post about commit message best-practices. ('The commit message should describe not just the "what" of the change but also the "why".')
Attachment #8862799 - Flags: review?(dholbert) → review+
Pushed by mpalmgren@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/a8efdd4a24dd
[css-grid] Disallow fit-content() in repeat(auto-fill/fit) track sizes (per the CSS Grid spec).  r=dholbert
https://hg.mozilla.org/mozilla-central/rev/a8efdd4a24dd
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: