wix-style-react
Version:
wix-style-react
26 lines (24 loc) • 988 B
JavaScript
const rangeInputWithLabelCompositeDriverFactory = ({ element }) => {
const label = element.childNodes[0].childNodes[0];
const hasLabel = label.tagName.toLowerCase() === 'label';
const firstInput = hasLabel
? element.childNodes[1].childNodes[0]
: element.childNodes[0].childNodes[0];
const lastInput = hasLabel
? element.childNodes[1].childNodes[1]
: element.childNodes[0].childNodes[1];
return {
exists: () => !!element,
getLabel: () => label.textContent,
hasLabel: () => label.tagName.toLowerCase() === 'label',
hasInputs: () => !!firstInput && !!lastInput,
getAttr: attrName => element.getAttribute(attrName),
getNumberOfChildren: () =>
hasLabel
? element.childNodes[1].childElementCount
: element.childNodes[0].childElementCount,
hasFieldLabelAttributes: () =>
!!element.querySelectorAll('[data-hook="field-label-attributes"]').length,
};
};
export default rangeInputWithLabelCompositeDriverFactory;