Skip to content

Commit 1221221

Browse files
wxiaoguangsilverwindGiteaBot
authored
Add "dir=auto" for input/textarea elements by default (#26735)
Co-authored-by: silverwind <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent d1dca38 commit 1221221

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

web_src/css/base.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ a.label,
478478
/* fix Fomantic's line-height cutting off "g" on Windows Chrome with Segoe UI */
479479
.ui.input > input {
480480
line-height: var(--line-height-default);
481+
text-align: start; /* Override fomantic's `text-align: left` to make RTL work via HTML `dir="auto"` */
481482
}
482483

483484
.ui.input.focus > input,

web_src/js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ import {onDomReady} from './utils/dom.js';
8484
import {initRepoIssueList} from './features/repo-issue-list.js';
8585
import {initCommonIssueListQuickGoto} from './features/common-issue-list.js';
8686
import {initRepoDiffCommitBranchesAndTags} from './features/repo-diff-commit.js';
87+
import {initDirAuto} from './modules/dirauto.js';
8788

8889
// Init Gitea's Fomantic settings
8990
initGiteaFomantic();
91+
initDirAuto();
9092

9193
onDomReady(() => {
9294
initGlobalCommon();

web_src/js/modules/dirauto.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// for performance considerations, it only uses performant syntax
2+
3+
function attachDirAuto(el) {
4+
if (el.type !== 'hidden' &&
5+
el.type !== 'checkbox' &&
6+
el.type !== 'radio' &&
7+
el.type !== 'range' &&
8+
el.type !== 'color') {
9+
el.dir = 'auto';
10+
}
11+
}
12+
13+
export function initDirAuto() {
14+
const observer = new MutationObserver((mutationList) => {
15+
const len = mutationList.length;
16+
for (let i = 0; i < len; i++) {
17+
const mutation = mutationList[i];
18+
const len = mutation.addedNodes.length;
19+
for (let i = 0; i < len; i++) {
20+
const addedNode = mutation.addedNodes[i];
21+
if (addedNode.nodeType !== Node.ELEMENT_NODE && addedNode.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) continue;
22+
attachDirAuto(addedNode);
23+
const children = addedNode.querySelectorAll('input, textarea');
24+
const len = children.length;
25+
for (let childIdx = 0; childIdx < len; childIdx++) {
26+
attachDirAuto(children[childIdx]);
27+
}
28+
}
29+
}
30+
});
31+
32+
const docNodes = document.querySelectorAll('input, textarea');
33+
const len = docNodes.length;
34+
for (let i = 0; i < len; i++) {
35+
attachDirAuto(docNodes[i]);
36+
}
37+
38+
observer.observe(document, {subtree: true, childList: true});
39+
}

0 commit comments

Comments
 (0)