- {/* We can't target pseudo-elements with the style prop, so we inject a tag here */}
-
-
{
- // Place the caret at the end of the current value
- if (innerRef.current) {
- const start = Math.min(innerRef.current.value.length, length - 1);
- const end = innerRef.current.value.length;
- innerRef.current.setSelectionRange(start, end);
- setSelectionRange([start, end]);
- }
- rest?.onFocus?.(event);
- }}
- onBlur={event => {
- setSelectionRange([-1, -1]);
- rest?.onBlur?.(event);
- }}
- onMouseOver={event => {
- if (!isFocused()) {
- setIsHovering(true);
- }
- props.onMouseOver?.(event);
- }}
- onMouseLeave={event => {
- setIsHovering(false);
- props.onMouseLeave?.(event);
- }}
- style={{
- ...inputStyle,
- clipPath: `inset(0 calc(1ch + ${passwordManagerOffset}px) 0 0)`,
- width: `calc(100% + 1ch + ${passwordManagerOffset}px)`,
- }}
- />
-
- {Array.from({ length }).map((_, i) => {
- const isHovered = isHovering && !isFocused();
- const isCursor = selectionRange[0] === selectionRange[1] && selectionRange[0] === i;
- const isSelected = (selectionRange[0] ?? -1) <= i && (selectionRange[1] ?? -1) > i;
-
- return (
-
- {render({
- value: String(props.value)[i] || '',
- status: isHovered ? 'hovered' : isCursor ? 'cursor' : isSelected ? 'selected' : 'none',
- index: i,
- })}
-
- );
- })}
-
-
- );
- },
-);
-
-/**
- * Handle updating the input selection range to ensure a single character is selected when moving the cursor, or if the input value changes.
- */
-function selectionRangeUpdater(cur: SelectionRange, inputRef: React.RefObject