visually-hidden-input
diceui-base/visually-hidden-inputFreeComponent
diceui/base publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/visually-hidden-input.jsonSource
1"use client";23import * as React from "react";45type InputValue = string[] | string;67interface VisuallyHiddenInputProps<T = InputValue>8 extends Omit<9 React.InputHTMLAttributes<HTMLInputElement>,10 "value" | "checked" | "onReset"11 > {12 value?: T;13 checked?: boolean;14 control: HTMLElement | null;15 bubbles?: boolean;16}1718function VisuallyHiddenInput<T = InputValue>(19 props: VisuallyHiddenInputProps<T>,20) {21 const {22 control,23 value,24 checked,25 bubbles = true,26 type = "hidden",27 style,28 ...inputProps29 } = props;3031 const isCheckInput = React.useMemo(32 () => type === "checkbox" || type === "radio" || type === "switch",33 [type],34 );35 const inputRef = React.useRef<HTMLInputElement>(null);3637 const prevValueRef = React.useRef<{38 value: T | boolean | undefined;39 previous: T | boolean | undefined;40 }>({41 value: isCheckInput ? checked : value,42 previous: isCheckInput ? checked : value,43 });4445 const prevValue = React.useMemo(() => {46 const currentValue = isCheckInput ? checked : value;47 if (prevValueRef.current.value !== currentValue) {48 prevValueRef.current.previous = prevValueRef.current.value;49 prevValueRef.current.value = currentValue;50 }51 return prevValueRef.current.previous;52 }, [isCheckInput, value, checked]);5354 const [controlSize, setControlSize] = React.useState<{55 width?: number;56 height?: number;57 }>({});5859 React.useLayoutEffect(() => {60 if (!control) {61 setControlSize({});62 return;63 }6465 setControlSize({66 width: control.offsetWidth,67 height: control.offsetHeight,68 });6970 if (typeof window === "undefined") return;7172 const resizeObserver = new ResizeObserver((entries) => {73 if (!Array.isArray(entries) || !entries.length) return;7475 const entry = entries[0];76 if (!entry) return;7778 let width: number;79 let height: number;8081 if ("borderBoxSize" in entry) {82 const borderSizeEntry = entry.borderBoxSize;83 const borderSize = Array.isArray(borderSizeEntry)84 ? borderSizeEntry[0]85 : borderSizeEntry;86 width = borderSize.inlineSize;87 height = borderSize.blockSize;88 } else {89 width = control.offsetWidth;90 height = control.offsetHeight;91 }9293 setControlSize({ width, height });94 });9596 resizeObserver.observe(control, { box: "border-box" });97 return () => {98 resizeObserver.disconnect();99 };100 }, [control]);101102// … truncated
Files it writes
More from diceui/base
All 192 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/base | Components | Free | 1 dep | |
| angle-sliderangle-slider | diceui/base | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/base | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/base | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/base | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/base | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/base | Components | Free | no deps | |
| color-pickercolor-picker | diceui/base | Components | Free | 1 dep · 2 files |
