Anchor positioning issue : misplacing elements (popovers) in RTL mode
Categories
(Core :: Layout: Positioned, defect)
Tracking
()
People
(Reporter: nina.gautreau, Unassigned)
Details
Attachments
(1 file)
|
1.64 KB,
text/html
|
Details |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:149.0) Gecko/20100101 Firefox/149.0
Steps to reproduce:
- create a section
- add a div with an id and attribute
popovercontaining a random text - add a button with attribute
popovertarget=<the id of the popover div> - style the popover div with
position-area: block-end;
reproduction here
Actual results:
when clicking the button, the popover is located below the button, centered
if you add the attribute dir="rtl" on the section, and click the button, the popover is not located where it should be (it can even be outside of the viewport !)
Expected results:
if you add the attribute dir="rtl" on the section, and click the button, the popover should be located below the button, centered (same behavior as in ltr mode)
(In reply to nina from comment #0)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:149.0) Gecko/20100101 Firefox/149.0
Steps to reproduce:
- create a section
- add a div with an id and attribute
popovercontaining a random text- add a button with attribute
popovertarget="<the id of the popover div>"- style the popover div with
position-area: block-end;reproduction here
Actual results:
when clicking the button, the popover is located below the button, centered
if you add the attribute
dir="rtl"on the section, and click the button, the popover is not located where it should be (it can even be outside of the viewport !)Expected results:
if you add the attribute
dir="rtl"on the section, and click the button, the popover should be located below the button, centered (same behavior as in ltr mode)
Comment 2•9 months ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Updated•9 months ago
|
Updated•9 months ago
|
Comment 3•9 months ago
|
||
This seems to be specific to popovers; I'm not seeing the same issue with other anchor-positioned elements.
Comment 4•3 months ago
|
||
I can reproduce a closely related popover-specific failure without RTL direction, using mixed writing modes instead. I have attached a minimal testcase.
The testcase has writing-mode: vertical-rl on the root, restores writing-mode: horizontal-tb on a local container, and uses an implicit popover anchor with position-area: bottom. In Firefox, the popover is placed far to the right of the button and outside the viewport. At a 768 × 720 viewport in Playwright's bundled Firefox 150.0.2, the popover center is about 825 px to the right of the button center. Chromium centers it below the button.
The single bottom keyword is specified to behave as bottom span-all. Spelling it explicitly as bottom span-all still reproduces the Firefox failure. Changing it to bottom center avoids the offscreen placement, although that selects a different positioning area and is therefore only an application workaround.
Expected: the popover should be centered immediately below its invoker.
This affects the live app at https://reader.miwake.app/.
Comment 5•2 days ago
|
||
This still reproduces in Firefox 160.0.1 (macOS), and it is wider than popovers in RTL pages. The common cause looks like this: when an anchor-positioned box's direction differs from its containing block's, Firefox misplaces it in the inline axis for every position-area keyword family, including physical keywords, which should not depend on direction at all. anchor() insets are placed correctly in the same setups.
Minimal testcase (attached: testcase.html; it prints the engine, the expected and actual numbers, and PASS/FAIL):
<!doctype html>
<style>
#a { position: absolute; left: 400px; top: 300px; width: 100px; height: 40px; anchor-name: --a; }
#s { inset: auto; margin: 0; width: 60px; height: 30px;
position-anchor: --a; position-area: span-all left; }
</style>
<div dir="rtl">
<button id="a"></button>
<div id="s" popover="manual"></div>
</div>
<script>s.showPopover()</script>
Expected: the popover's right edge sits on the anchor's left edge (left = 340px). Physical left takes no direction from anywhere.
Actual (Firefox 160.0.1): left = 0px. Chrome 158 and Safari 27.0.1: 340px.
Comparison across 14 cases (attached: comparison.html, which grades each case in-page; side-by-side.png shows all three browsers). Popover inside <div dir=rtl> on an ltr page unless noted:
| # | Case | Firefox 160.0.1 | Chrome 158 | Safari 27.0.1 |
|---|---|---|---|---|
| 1 | position-area: span-all left |
wrong (0, expected 62) | correct | correct |
| 2 | position-area: top span-all |
wrong (-369, expected 369) | correct | correct |
| 3 | span-all inline-start (plain logical) |
wrong (0, expected 546) | correct | correct |
| 4 | span-all self-inline-start |
wrong (896, expected 918) | correct | correct |
| 5 | position-try-fallbacks |
wrong (-776, expected 82) | correct | correct |
| 6 | physical keyword, direction set by stylesheet, not dir |
wrong (0, expected 304) | correct | correct |
| 7 | plain logical, direction set by stylesheet | wrong (0, expected 546) | correct | correct |
| 8 | anchor() physical insets |
correct | correct | correct |
| 9 | inset-inline-start: anchor(start) |
correct | correct | correct |
| 10 | anchor(self-start) |
correct | correct | correct |
| 11 | control: no direction mismatch | correct | correct | correct |
| 12 | control: <html dir=rtl> in an iframe |
correct | correct | correct |
| 13 | control: position: absolute box in an rtl block |
correct | correct | correct |
| 14 | position: absolute box, ltr element inside an rtl containing block |
wrong (354, expected 304) | correct | correct |
Firefox passes 6 of 14, and Chrome and Safari pass 14 of 14. Every failure is a box whose direction differs from its containing block's (cases 1–7 and 14). Every pass either has no mismatch (11–13) or uses anchor() (8–10). Case 14 shows it is not specific to popovers (comment 3): a position: absolute box fails too, once its direction differs from its containing block's. Comment 4's mixed writing-mode testcase looks like the same cause.
Spec (CSS Anchor Positioning 1, §3.1.2): plain logical keywords "refer to the writing mode of the box's containing block"; self-* keywords "refer to the box's own writing mode"; physical keywords have no direction dependence. For a popover, the containing block is the viewport (ltr here). Each expected value above follows from that; the physical-keyword cases are the clearest.
Existing WPT coverage misses this. position-area-wm-dir.html and position-area-align-justify-wm-dir.html set the direction on the positioned box itself with no mismatch against an ltr ancestor, and they pass in Firefox. I have a reftest ready, css/css-anchor-position/position-area-rtl-mismatch-001.html with its -ref.html. It matches in Chrome 158 and Safari 27.0.1, and it fails in Firefox 160.0.1 (the box renders at x 0–59 instead of 40–99). I'm happy to upstream it.
Possibly related: bug 2050071 (logical inline keywords in RTL) and bug 1995256 (flip-inline/flip-block use of the containing block's writing mode).
Environment: macOS 27, Firefox 160.0.1 release with a fresh profile, Chrome 158.0.8127.38, Safari 27.0.1. Viewport 1000×700, 1px tolerance.
Description
•