-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-svg-span
- Loading branch information
Showing
9 changed files
with
201 additions
and
94 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let ariaIdCounter = 0; | ||
|
||
export function generateAriaId() { | ||
return `_aria_auto_id_${ariaIdCounter++}`; | ||
} |
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,38 @@ | ||
import $ from 'jquery'; | ||
import {generateAriaId} from './base.js'; | ||
|
||
const ariaPatchKey = '_giteaAriaPatchCheckbox'; | ||
const fomanticCheckboxFn = $.fn.checkbox; | ||
|
||
// use our own `$.fn.checkbox` to patch Fomantic's checkbox module | ||
export function initAriaCheckboxPatch() { | ||
if ($.fn.checkbox === ariaCheckboxFn) throw new Error('initAriaCheckboxPatch could only be called once'); | ||
$.fn.checkbox = ariaCheckboxFn; | ||
ariaCheckboxFn.settings = fomanticCheckboxFn.settings; | ||
} | ||
|
||
// the patched `$.fn.checkbox` checkbox function | ||
// * it does the one-time attaching on the first call | ||
function ariaCheckboxFn(...args) { | ||
const ret = fomanticCheckboxFn.apply(this, args); | ||
for (const el of this) { | ||
if (el[ariaPatchKey]) continue; | ||
attachInit(el); | ||
} | ||
return ret; | ||
} | ||
|
||
function attachInit(el) { | ||
// Fomantic UI checkbox needs to be something like: <div class="ui checkbox"><label /><input /></div> | ||
// It doesn't work well with <label><input />...</label> | ||
// To make it work with aria, the "id"/"for" attributes are necessary, so add them automatically if missing. | ||
// In the future, refactor to use native checkbox directly, then this patch could be removed. | ||
el[ariaPatchKey] = {}; // record that this element has been patched | ||
const label = el.querySelector('label'); | ||
const input = el.querySelector('input'); | ||
if (!label || !input || input.getAttribute('id')) return; | ||
|
||
const id = generateAriaId(); | ||
input.setAttribute('id', id); | ||
label.setAttribute('for', id); | ||
} |
Oops, something went wrong.