wix-style-react
Version:
103 lines (89 loc) • 2.2 kB
JavaScript
import { dataHooks } from './constants';
export var radioDriverFactory = function radioDriverFactory(_ref) {
var element = _ref.element,
eventTrigger = _ref.eventTrigger;
var byHook = function byHook(hook) {
return element.querySelector("[data-hook*=\"".concat(hook, "\"]"));
};
var getInput = function getInput() {
return byHook(dataHooks.input);
};
var getIcon = function getIcon() {
return byHook(dataHooks.icon);
};
var getLabel = function getLabel() {
return byHook(dataHooks.label);
};
return {
exists: function exists() {
return !!element;
},
/**
/* Triggers a keyDown event on the radio input
* @param {string} key
* @return {void}
*/
keyDown: function keyDown(key) {
return eventTrigger.keyDown(getInput(), {
key: key
});
},
/**
/* Triggers click event on radio
* @return {void}
*/
click: function click() {
return eventTrigger.click(element);
},
/**
* Gets value of radio input
* @return {string}
*/
getValue: function getValue() {
return getInput().getAttribute('value');
},
/**
* Gets name of radio input
* @return {string}
*/
getName: function getName() {
return getInput().getAttribute('name');
},
/**
* Gets id of radio input
* @return {string}
*/
getId: function getId() {
return getInput().getAttribute('id');
},
/**
* Checks if icon of radio exists
* @return {boolean}
*/
iconExists: function iconExists() {
return !!getIcon();
},
/**
* Checks if label of radio exists
* @return {boolean}
*/
labelExists: function labelExists() {
return !!getLabel();
},
/**
* Checks if radio is checked
* @return {boolean}
*/
isChecked: function isChecked() {
return element.getAttribute('data-checked') === 'true';
},
/**
* Checks if radio is disabled
* @return {boolean}
*/
isDisabled: function isDisabled() {
return element.getAttribute('data-disabled') === 'true';
}
};
};
export default radioDriverFactory;