label-content-name-mismatch: split words by language (ACT step 4) so CJK labels without spaces are found
Summary
The ACT label in name algorithm splits text into words in step 4 "according to the word segmentation rules for the language of the element", and notes that "In languages such as Thai, Chinese, and Japanese, [a whitespace split] won't" work. axe splits on whitespace only, so in languages written without spaces a visible label that is one word of a longer accessible name is reported as a violation. The same pattern passes in English.
This is the step-4 counterpart of #5308, which fixed the punctuation side of "passes in English, fails in CJK".
Steps to reproduce
<html lang="ja">
<button id="ja" aria-label="サイト内を検索">検索</button>
<a id="zh" lang="zh-Hant" href="/b" aria-label="範例公司官網另開新視窗">另開新視窗</a>
<button id="en" lang="en" aria-label="Search this site">Search</button>
</html>await axe.run(document, { runOnly: { type: 'rule', values: ['label-content-name-mismatch'] } });Expected: all three pass. Actual (on develop eb854ed3, and with #5419 applied):
{ "violations": ["#ja", "#zh"], "passes": ["#en"] }Each CJK string becomes a single token, so 検索 is compared against the whole of サイト内を検索.
Possible approaches
A. Intl.Segmenter with word granularity, using the element's language. It follows the ACT text literally, and Chrome 153 segments the repro as expected: 検索 → [検索] inside [サイト, 内, を, 検索], and 另開新視窗 → [另開, 新, 視窗] inside [範例, 公司, 官, 網, 另開, 新, 視窗]. Tradeoffs:
- The results depend on each browser's ICU dictionary, so the same page could give different results in different browsers.
- A short label might segment differently on its own than inside a longer name.
- IE11 has no
Intl.Segmenter, so it needs a feature-detect with a whitespace fallback.
B. Substring containment for scripts written without spaces (Han, kana, Hangul, Thai). It's deterministic across browsers, but it matches inside words (送信 would be found in 送信者), which ACT's token equality would not allow.
Related
- #5308 / #5419: steps 2 and 3 of the same algorithm.
- #5203: closed on the ACT test corpus, which has no step-4 example.
Source: dequelabs/axe-core