Bug 227196

Summary: document.documentElement.removeAttribute('dir') won't reset to previous state
Product: WebKit Reporter: diegocardoso <diegopc86>
Component: Layout and RenderingAssignee: Nobody <webkit-unassigned>
Status: RESOLVED CONFIGURATION CHANGED    
Severity: Normal CC: ahmad.saleem792, bfulgham, mmaxfield, simon.fraser, webkit-bug-importer, zalan
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: Mac (Intel)   
OS: macOS 11   
See Also: https://bugs.webkit.org/show_bug.cgi?id=257133

Description diegocardoso 2021-06-20 12:34:56 PDT
If you have a page in LTR mode and call `document.documentElement.setAttribute('dir', 'rtl')` to force the page to be in RTL mode, you would expect that calling `document.documentElement.removeAttribute('dir')` restores it to the previous state. But in Safari, unlike Chrome and Firefox, nothing happens and the direction mode remains on RTL. You can force it to go back to LRT by calling `document.documentElement.setAttribute('dir', 'ltr').

I couldn't find on the specs (https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute) any description of how it should behave on this case, but since other browsers that I tested work similarly, meaning that it falls back to the default direction mode, I decided to fill this bug.

You can try it on this small example I created: https://jsfiddle.net/diegocardoso/chm7yk5e/7/
Comment 1 Radar WebKit Bug Importer 2021-06-27 12:35:17 PDT
<rdar://problem/79842142>
Comment 2 Ahmad Saleem 2023-05-23 02:44:08 PDT
I am unable to reproduce this bug in Safari 16.5, where ticking makes it RTL while unticking make it go back to original state and it matches with Chrome Canary 115 and Firefox Nightly 115.

Marking this as "RESOLVED CONFIGURATION CHANGED", if it is still an issue, please reopen with updated test case / reduction.