UNPKG

wix-style-react

Version:
46 lines (45 loc) 2.23 kB
"use strict"; exports.__esModule = true; exports.toggleSwitchDriverFactory = void 0; var toggleSwitchDriverFactory = _ref => { var { element, eventTrigger } = _ref; var checkbox = element && element.querySelector('input'); return { /** Checks if element exists */ exists: () => !!element, /** Triggers change */ click: () => { // jsdom doesn't simulate checkboxes well: checkbox.click() updates .checked even // if the component is controlled, it also doesn't generate onChange() and doesn't // respect .disabled if ((checkbox == null ? void 0 : checkbox.getAttribute('data-disabled')) !== 'true') { eventTrigger.change(checkbox); } }, /** Returns a boolean indicating if the toggleSwitch is checked */ isChecked: () => checkbox == null ? void 0 : checkbox.checked, /** Returns a boolean indicating if the toggleSwitch is disabled */ isDisabled: () => (element == null ? void 0 : element.getAttribute('data-disabled')) === 'true', /** Returns the toggle icon inside the knob */ getKnobIcon: () => element == null ? void 0 : element.querySelector('[data-hook="knob-icon"]'), /** Returns whether the toggle has an icon */ hasKnobIcon: () => !!element.querySelector('[data-hook="knob-icon"]').innerHTML, /** Returns the id of the input */ getId: () => checkbox == null ? void 0 : checkbox.id, /** Returns the tab index */ getTabIndex: () => checkbox == null ? void 0 : checkbox.tabIndex, /** Returns the computed styles object of the root component */ getRootStyles: () => window.getComputedStyle(element), /** Returns the computed styles object of the track */ getTrackStyles: () => window.getComputedStyle(element.querySelector('[data-hook="track"]')), /** Returns the computed styles object of the knob */ getKnobStyles: () => window.getComputedStyle(element.querySelector('[data-hook="knob"]')), /** Returns the computed styles object of the knob icon */ getKnobIconStyles: () => window.getComputedStyle(element.querySelector('[data-hook="knob-icon"]')) }; }; exports.toggleSwitchDriverFactory = toggleSwitchDriverFactory; //# sourceMappingURL=ToggleSwitchCore.driver.js.map