-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add "dir=auto" for input/textarea elements by default #26735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
697ebcc
fix
wxiaoguang 93abd9c
exclude some input types
wxiaoguang f1366c0
add css fix
silverwind 76ef3c8
remove not, add color type
silverwind 3bc452b
improve perf, add benchmark logging for debug
silverwind 9262691
add pre-check with querySelector
silverwind f839933
optimize
wxiaoguang 17b1c3e
Update web_src/js/webcomponents/webcomponents.js
silverwind ccfa6a3
Merge branch 'main' into dir-auto
wxiaoguang ae6c5ef
Merge branch 'main' into dir-auto
wxiaoguang 6d1dc06
Merge branch 'main' into dir-auto
silverwind 21494b4
use i
silverwind b853d67
use Set
silverwind 10cb39c
cache for lengths, remove measuring code
silverwind f68e0fc
Merge branch 'main' into dir-auto
GiteaBot f4804a5
Merge branch 'main' into dir-auto
GiteaBot 2fccbce
Merge branch 'main' into dir-auto
GiteaBot e78c181
switch back to if
silverwind c24d544
use i in inner loop as well
silverwind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// for performance considerations, it only uses performant syntax | ||
|
||
function attachDirAuto(el) { | ||
if (el.type !== 'hidden' && | ||
el.type !== 'checkbox' && | ||
el.type !== 'radio' && | ||
el.type !== 'range' && | ||
el.type !== 'color') { | ||
el.dir = 'auto'; | ||
} | ||
} | ||
|
||
export function initDirAuto() { | ||
const observer = new MutationObserver((mutationList) => { | ||
const len = mutationList.length; | ||
for (let i = 0; i < len; i++) { | ||
const mutation = mutationList[i]; | ||
const len = mutation.addedNodes.length; | ||
for (let i = 0; i < len; i++) { | ||
const addedNode = mutation.addedNodes[i]; | ||
if (addedNode.nodeType !== Node.ELEMENT_NODE && addedNode.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) continue; | ||
attachDirAuto(addedNode); | ||
const children = addedNode.querySelectorAll('input, textarea'); | ||
const len = children.length; | ||
for (let childIdx = 0; childIdx < len; childIdx++) { | ||
attachDirAuto(children[childIdx]); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const docNodes = document.querySelectorAll('input, textarea'); | ||
const len = docNodes.length; | ||
for (let i = 0; i < len; i++) { | ||
attachDirAuto(docNodes[i]); | ||
} | ||
|
||
observer.observe(document, {subtree: true, childList: true}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.