Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eleven-apes-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Prevent focus reset on date/time input clicks in Safari.
2 changes: 1 addition & 1 deletion packages/react/src/TextInput/TextInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Playground = (args: FormControlArgs<TextInputProps>) => {
<form className={classes.Container}>
<FormControl {...parentArgs}>
<FormControl.Label {...labelArgs} />
<TextInput value={value} onChange={handleChange} {...args} />
<TextInput value={value} onChange={handleChange} onInput={handleChange} {...args} />
{captionArgs.children && <FormControl.Caption {...captionArgs} />}
{validationArgs.children && validationArgs.variant && (
<FormControl.Validation {...validationArgs} variant={validationArgs.variant} />
Expand Down
11 changes: 9 additions & 2 deletions packages/react/src/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
loading && (loaderPosition === 'leading' || Boolean(LeadingVisual && loaderPosition !== 'trailing'))
const showTrailingLoadingIndicator =
loading && (loaderPosition === 'trailing' || Boolean(loaderPosition === 'auto' && !LeadingVisual))
const focusInput: MouseEventHandler = () => {
inputRef.current?.focus()

// Date/time input types that have segment-based focus
const isSegmentedInputType = type === 'date' || type === 'time' || type === 'datetime-local'

const focusInput: MouseEventHandler = e => {
// Don't call focus() if the input itself was clicked on date/time inputs.
if (e.target !== inputRef.current || !isSegmentedInputType) {
inputRef.current?.focus()
}
}
const leadingVisualId = useId()
const trailingVisualId = useId()
Expand Down
Loading