Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/drive/page_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ export class PageRenderer extends Renderer {

#setLanguage() {
const { documentElement } = this.currentSnapshot
const { lang } = this.newSnapshot
const { dir, lang } = this.newSnapshot

if (lang) {
documentElement.setAttribute("lang", lang)
} else {
documentElement.removeAttribute("lang")
}
if (dir) {
documentElement.setAttribute("dir", dir)
} else {
documentElement.removeAttribute("dir")
}
}

async mergeHead() {
Expand Down
4 changes: 4 additions & 0 deletions src/core/drive/page_snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export class PageSnapshot extends Snapshot {
return this.documentElement.getAttribute("lang")
}

get dir() {
return this.documentElement.getAttribute("dir")
}

get headElement() {
return this.headSnapshot.element
}
Expand Down
12 changes: 12 additions & 0 deletions src/tests/fixtures/dir_rtl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html dir="rtl">
<head>
<meta charset="utf-8" />
<title>Turbo</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
</head>
<body>
<h1>html[dir="rtl"]</h1>
</body>
</html>
1 change: 1 addition & 0 deletions src/tests/fixtures/rendering.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h1>Rendering</h1>
<p><a id="delayed-link" href="/__turbo/delayed_response">Delayed link</a></p>
<p><a id="redirect-link" href="/__turbo/redirect">Redirect link</a></p>
<p><a id="es_locale_link" href="/src/tests/fixtures/es_locale.html">Change html[lang]</a></p>
<p><a id="dir-rtl" href="/src/tests/fixtures/dir_rtl.html">Change html[dir]</a></p>
<form>
<input type="text" id="text-input">
<input type="radio" id="radio-input">
Expand Down
6 changes: 6 additions & 0 deletions src/tests/functional/rendering_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ test("changes the html[lang] attribute", async ({ page }) => {
await expect(page.locator("html")).toHaveAttribute("lang", "es")
})

test("changes the html[dir] attribute", async ({ page }) => {
await page.click("#dir-rtl")

await expect(page.locator("html")).toHaveAttribute("dir", "rtl")
})

test("accumulates script elements in head", async ({ page }) => {
const assetElements = () => page.$$('script')
const originalElements = await assetElements()
Expand Down