-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: merge CustomChoiceGroupMixin with ChoiceGroupMixin; enhance cod…
…e readibility
- Loading branch information
Showing
23 changed files
with
857 additions
and
945 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
'@lion/ui': patch | ||
--- | ||
|
||
merge CustomChoiceGroupMixin functionality into ChoiceGroupMixin |
This file contains 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 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
49 changes: 49 additions & 0 deletions
49
packages/ui/components/combobox/src/utils/fixOptionA11yForSafari.js
This file contains 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,49 @@ | ||
/** | ||
* @typedef {import('@lion/ui/listbox.js').LionOption} LionOption | ||
*/ | ||
|
||
const matchA11ySpanReverseFns = new WeakMap(); | ||
|
||
/** | ||
* For Safari, we need to add a label to the element | ||
* Create a wrapping span: => `<my-option><b>my</b> text</my-option>` | ||
* becomes `<my-option><span aria-label="my text"><b>my</b> text</span></my-option>` | ||
* @param {Element} option | ||
*/ | ||
export function fixOptionA11yForSafari(option) { | ||
if (!option.textContent) { | ||
return; | ||
} | ||
|
||
// [1] Wrap the content in a span with an aria-label | ||
// `<my-option><b>my</b> text</my-option>` => | ||
// `<my-option><span aria-label="my text"><b>my</b> text</span></my-option>` | ||
const a11ySpan = document.createElement('span'); | ||
a11ySpan.setAttribute('aria-label', option.textContent.replace(/\s+/g, ' ')); | ||
for (const childNode of Array.from(option.childNodes)) { | ||
a11ySpan.appendChild(childNode); | ||
} | ||
option.appendChild(a11ySpan); | ||
|
||
// [2] Store a function to call later, that does: | ||
// `<my-option><span aria-label="my text"><b>my</b> text</span></my-option>` => | ||
// `<my-option><b>my</b> text</my-option>` | ||
matchA11ySpanReverseFns.set(option, () => { | ||
for (const childNode of Array.from(a11ySpan.childNodes)) { | ||
option.appendChild(childNode); | ||
} | ||
if (option.contains(a11ySpan)) { | ||
option.removeChild(a11ySpan); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @param {Element} option | ||
*/ | ||
export function cleanupOptionA11yForSafari(option) { | ||
if (matchA11ySpanReverseFns.has(option)) { | ||
matchA11ySpanReverseFns.get(option)(); | ||
} | ||
matchA11ySpanReverseFns.delete(option); | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/ui/components/combobox/test/lion-combobox-integrations.test.js
This file contains 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { runListboxMixinSuite } from '@lion/ui/listbox-test-suites.js'; | ||
import { runChoiceGroupMixinSuite } from '@lion/ui/form-core-test-suites.js'; | ||
import '@lion/ui/define/lion-combobox.js'; | ||
import { runCustomChoiceGroupMixinSuite } from '../../form-core/test-suites/choice-group/CustomChoiceGroupMixin.suite.js'; | ||
|
||
runListboxMixinSuite({ tagString: 'lion-combobox' }); | ||
runCustomChoiceGroupMixinSuite({ | ||
runChoiceGroupMixinSuite({ | ||
parentTagString: 'lion-combobox', | ||
childTagString: 'lion-option', | ||
}); |
Oops, something went wrong.