UNPKG

wix-style-react

Version:
37 lines 2.05 kB
export const toggleSwitchDriverFactory = ({ element, eventTrigger, }) => { const 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?.getAttribute('data-disabled') !== 'true') { eventTrigger.change(checkbox); } }, /** Returns a boolean indicating if the toggleSwitch is checked */ isChecked: () => checkbox?.checked, /** Returns a boolean indicating if the toggleSwitch is disabled */ isDisabled: () => element?.getAttribute('data-disabled') === 'true', /** Returns the toggle icon inside the knob */ getKnobIcon: () => 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?.id, /** Returns the tab index */ getTabIndex: () => 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"]')), }; }; //# sourceMappingURL=ToggleSwitchCore.driver.js.map