radio.js 913 B

12345678910111213141516171819202122232425
  1. import '../utils/dataTransfer/Clipboard.js';
  2. import { isDisabled } from '../utils/misc/isDisabled.js';
  3. import { getWindow } from '../utils/misc/getWindow.js';
  4. import { focusElement } from './focus.js';
  5. function walkRadio(instance, el, direction) {
  6. const window = getWindow(el);
  7. const group = Array.from(el.ownerDocument.querySelectorAll(el.name ? `input[type="radio"][name="${window.CSS.escape(el.name)}"]` : `input[type="radio"][name=""], input[type="radio"]:not([name])`));
  8. for(let i = group.findIndex((e)=>e === el) + direction;; i += direction){
  9. if (!group[i]) {
  10. i = direction > 0 ? 0 : group.length - 1;
  11. }
  12. if (group[i] === el) {
  13. return;
  14. }
  15. if (isDisabled(group[i])) {
  16. continue;
  17. }
  18. focusElement(group[i]);
  19. instance.dispatchUIEvent(group[i], 'click');
  20. return;
  21. }
  22. }
  23. export { walkRadio };