From 763cf87749398e1951815333d3b06faa881d87a8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 20 Dec 2025 20:07:08 -0600 Subject: [PATCH] Improve display of ExternalInput on Safari --- src/components/ui/external-input.tsx | 34 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/components/ui/external-input.tsx b/src/components/ui/external-input.tsx index c8d65276..680483a5 100644 --- a/src/components/ui/external-input.tsx +++ b/src/components/ui/external-input.tsx @@ -1,4 +1,4 @@ -import * as React from "react" +import { forwardRef, useState, useEffect, useRef } from "react" import { Eye, EyeOff, ExternalLink } from "lucide-react" import { cn } from "@/lib/utils" @@ -11,10 +11,12 @@ interface ExternalInputProps extends Omit( +const ExternalInput = forwardRef( ({ className, type, url, urlTitle, value, ...props }, ref) => { - const [showPassword, setShowPassword] = React.useState(false) - const [isFocused, setIsFocused] = React.useState(false) + const [showPassword, setShowPassword] = useState(false) + const [isFocused, setIsFocused] = useState(false) + const [buttonWidth, setButtonWidth] = useState(0) + const buttonRef = useRef(null) // Determine if we have a value (works for both controlled and uncontrolled) const hasValue = Boolean(value || (props.defaultValue && !value)) @@ -23,15 +25,34 @@ const ExternalInput = React.forwardRef( const showEyeToggle = isPasswordType && hasValue const showExternalButton = url && urlTitle && !hasValue + // Measure the button width when it's rendered + useEffect(() => { + if (showExternalButton && buttonRef.current) { + const width = buttonRef.current.offsetWidth + setButtonWidth(width) + } else { + setButtonWidth(0) + } + }, [showExternalButton, urlTitle]) + + // Calculate padding-right based on what's showing + const paddingRight = showEyeToggle + ? '2.5rem' // 40px for eye toggle + : showExternalButton && buttonWidth > 0 + ? `${buttonWidth + 8}px` // button width + 8px spacing + : undefined + return (
{ @@ -61,6 +82,7 @@ const ExternalInput = React.forwardRef( )} {showExternalButton && (