@testing-library/user-event
Version:
Fire events the same way the user does
29 lines (24 loc) • 993 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var index = require('../../event/index.js');
var focus = require('../focus/focus.js');
var getWindow = require('../misc/getWindow.js');
var isDisabled = require('../misc/isDisabled.js');
function walkRadio(config, el, direction) {
const window = getWindow.getWindow(el);
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])`));
for(let i = group.findIndex((e)=>e === el) + direction;; i += direction){
if (!group[i]) {
i = direction > 0 ? 0 : group.length - 1;
}
if (group[i] === el) {
return;
}
if (isDisabled.isDisabled(group[i])) {
continue;
}
focus.focus(group[i]);
index.dispatchUIEvent(config, group[i], 'click');
}
}
exports.walkRadio = walkRadio;