({
label,
description,
value,
placeholder,
settingId,
commitOnBlur = false,
onChange
}: {
label: string
description?: string
value: string
placeholder?: string
settingId?: string
commitOnBlur?: boolean
onChange: (next: string | null) => void
})
| 4210 | |
| 4211 | |
| 4212 | function TextInputRow({ |
| 4213 | label, |
| 4214 | description, |
| 4215 | value, |
| 4216 | placeholder, |
| 4217 | settingId, |
| 4218 | commitOnBlur = false, |
| 4219 | onChange |
| 4220 | }: { |
| 4221 | label: string |
| 4222 | description?: string |
| 4223 | value: string |
| 4224 | placeholder?: string |
| 4225 | settingId?: string |
| 4226 | commitOnBlur?: boolean |
| 4227 | onChange: (next: string | null) => void |
| 4228 | }): JSX.Element { |
| 4229 | const [draft, setDraft] = useState(value) |
| 4230 | const [focused, setFocused] = useState(false) |
| 4231 | |
| 4232 | useEffect(() => { |
| 4233 | if (!commitOnBlur || !focused) setDraft(value) |
| 4234 | }, [commitOnBlur, focused, value]) |
| 4235 | |
| 4236 | const commit = (raw: string): void => { |
| 4237 | const next = raw.trim() |
| 4238 | if (commitOnBlur && next === value) return |
| 4239 | onChange(next ? next : null) |
| 4240 | } |
| 4241 | |
| 4242 | return ( |
| 4243 | <div |
| 4244 | className="flex items-center justify-between gap-5 px-5 py-4" |
| 4245 | {...settingsSearchTargetProps(settingId)} |
| 4246 | > |
| 4247 | <div className="min-w-0 flex-1"> |
| 4248 | <div className="text-sm font-medium text-ink-900">{label}</div> |
| 4249 | {description && <div className="mt-1 text-xs leading-5 text-ink-500">{description}</div>} |
| 4250 | </div> |
| 4251 | <input |
| 4252 | value={commitOnBlur ? draft : value} |
| 4253 | onFocus={() => setFocused(true)} |
| 4254 | onChange={(e) => { |
| 4255 | if (commitOnBlur) { |
| 4256 | setDraft(e.target.value) |
| 4257 | return |
| 4258 | } |
| 4259 | commit(e.target.value) |
| 4260 | }} |
| 4261 | onBlur={(e) => { |
| 4262 | if (!commitOnBlur) return |
| 4263 | setFocused(false) |
| 4264 | commit(e.target.value) |
| 4265 | }} |
| 4266 | onKeyDown={(e) => { |
| 4267 | if (!commitOnBlur) return |
| 4268 | if (e.key === 'Enter' && !isImeComposing(e)) e.currentTarget.blur() |
| 4269 | if (e.key === 'Escape') { |
nothing calls this directly
no test coverage detected