UNPKG

@postenbring/hedwig-react

Version:

React components for [Hedwig Design System](https://github.com/bring/hedwig-design-system).

69 lines (68 loc) 2.35 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/form/error-summary/focus.ts var focus_exports = {}; __export(focus_exports, { focusWithLegendOrLabelInViewport: () => focusWithLegendOrLabelInViewport }); module.exports = __toCommonJS(focus_exports); function focusWithLegendOrLabelInViewport(id) { var _a; const input = document.getElementById(id); if (!input) { return false; } const legendOrLabel = (_a = maybeLegendForInput(input)) != null ? _a : labelForInput(input); if (!legendOrLabel) { return false; } legendOrLabel.scrollIntoView(); input.focus({ preventScroll: true }); return true; } function maybeLegendForInput(input) { const fieldset = input.closest("fieldset"); if (!fieldset) { return null; } const legend = fieldset.querySelector("legend"); if (!legend) { return null; } if (input instanceof HTMLInputElement && (input.type === "checkbox" || input.type === "radio")) { return legend; } const legendTop = legend.getBoundingClientRect().top; const inputRect = input.getBoundingClientRect(); if (inputRect.height && window.innerHeight) { const inputBottom = inputRect.top + inputRect.height; if (inputBottom - legendTop < window.innerHeight / 2) { return legend; } } } function labelForInput(input) { var _a; return (_a = document.querySelector(`label[for='${input.getAttribute("id")}']`)) != null ? _a : input.closest("label"); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { focusWithLegendOrLabelInViewport }); //# sourceMappingURL=focus.js.map