Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unset should unset readOnly date field from custom input component #8192

Merged
merged 4 commits into from
Jan 7, 2025
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-nested-ternary */

import {TextInput} from '@sanity/ui'
import {
type FocusEvent,
type ForwardedRef,
Expand Down Expand Up @@ -105,9 +104,7 @@ export const CommonDateTimeInput = forwardRef(function CommonDateTimeInput(
? formatInputValue(parseResult.date)
: value

return readOnly ? (
<TextInput value={inputValue} readOnly />
) : (
return (
<DateTimeInput
{...restProps}
calendarLabels={props.calendarLabels}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const DateTimeInput = forwardRef(function DateTimeInput(
selectTime,
timeStep,
calendarLabels,
readOnly,
constrainSize = true,
...rest
} = props
Expand Down Expand Up @@ -77,7 +78,7 @@ export const DateTimeInput = forwardRef(function DateTimeInput(

const handleClick = useCallback(() => setPickerOpen(true), [])

const suffix = (
const suffix = readOnly ? null : (
<Flex style={{padding: '5px'}}>
<Button
aria-label={calendarLabels.ariaLabel}
Expand All @@ -96,6 +97,7 @@ export const DateTimeInput = forwardRef(function DateTimeInput(
<LazyTextInput
ref={ref}
{...rest}
readOnly={readOnly}
value={inputValue}
onChange={onInputChange}
suffix={
Expand Down Expand Up @@ -126,7 +128,7 @@ export const DateTimeInput = forwardRef(function DateTimeInput(
placement="bottom"
ref={popoverRef}
>
{suffix}
<>{suffix}</>
</Popover>
</LayerProvider>
) : (
Expand Down
Loading