Closed Bug 1448248 Opened 7 years ago Closed 2 years ago

Implement CSS attr(<attr-name>, <attr-fallback>)

Categories

(Core :: CSS Parsing and Computation, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
119 Branch
Tracking Status
relnote-firefox --- 119+
firefox119 --- fixed

People

(Reporter: sebo, Assigned: canadahonk)

References

(Blocks 1 open bug, )

Details

(Keywords: dev-doc-complete)

Attachments

(1 file)

The CSS Values and Units Module Level 3 extends the attr() function to optionally specify a fallback value, which is used if the named attribute is missing, or its value cannot be parsed into the given type or is invalid/out-of-range for the property. This bug is meant to implement the basic functionality of the fallback value for the case the attribute is missing. Sebastian
Priority: -- → P3
Severity: normal → S3

Implemented support for a fallback in CSS attr funcs
(attr(<attr-name>, <attr-fallback>))

Spec: https://drafts.csswg.org/css-values-5/#attr-notation

WIP. Todo:

  • Parse fallback into variable
  • Use fallback in C++
  • Add WPT tests
Attachment #9330947 - Attachment description: WIP: Bug 1448248 - Implement CSS attr func fallback → Bug 1448248 - Implement CSS attr func fallback
Assignee: nobody → oj
Status: NEW → ASSIGNED
Attachment #9330947 - Attachment description: Bug 1448248 - Implement CSS attr func fallback → WIP: Bug 1448248 - Implement CSS attr func fallback
Attachment #9330947 - Attachment description: WIP: Bug 1448248 - Implement CSS attr func fallback → Bug 1448248 - Implement CSS attr() fallback
Blocks: 1854104
Pushed by oj@oojmed.com: https://hg.mozilla.org/integration/autoland/rev/a14395d9ad06 Implement CSS attr() fallback r=emilio
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/42079 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 119 Branch
Upstream PR merged by moz-wptsync-bot

Release Note Request (optional, but appreciated)
[Why is this notable]: New CSS feature supported
[Affects Firefox for Android]: Yes
[Suggested wording]: The CSS attr() function now supports a fallback parameter (eg attr(foobar, "Default value")). First browser to implement, and ship.
[Links (documentation, blog post, etc)]: None yet.

relnote-firefox: --- → ?

Added to 119 beta release notes (https://www.mozilla.org/en-US/firefox/119.0beta/releasenotes/) as well as the Draft release notes for 119

I don't know if this was intentional, but I don't think that this works.

Consider the following:

<style>
p { background-color: green; padding: attr(data-padding px, 10px); margin: 20px; }
</style>
<p>This has the default padding.</p>
<p data-padding=0>This has no padding.</p>
<p data-padding=30>This has triple padding.</p>

I see no padding in Firefox. Not 10px of padding. Chromium is fine.

The following works, which suggests that this is probably a parsing thing.

<style>
    div::after { content: attr(data-after, "nothing"); }
</style>
<div>The fox says:</div>
<div data-after="yo">The fox says:</div>
Flags: needinfo?(emilio)

Firefox still only supports attr() in the content property, at the moment. See bug 435426 and the ones blocking it for the extensions to it and letting it apply to other properties. (The one for your example is bug 1871823.)

Sebastian

Flags: needinfo?(emilio)

This works, but we only currently support attr() on the content property. Bug 435426 which is being worked on at the moment will fix your test case.

Hah, midaired, thx Sebastian :)

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: