Skip to content

Commit

Permalink
jeremy's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
HBS999 committed Nov 19, 2024
1 parent 1b39d47 commit 50941a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/time-field/time-field-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export interface TimeFieldContextValue {
granularity: Accessor<TimeFieldGranularity>;
hideTimeZone: Accessor<boolean>;
shouldForceLeadingZeros: Accessor<boolean>;
placeholderValue: Accessor<TimeValue>;
placeholderTime: Accessor<TimeValue>;
placeholderValue: Accessor<TimeValue | undefined>;
defaultTimeZone: Accessor<string | undefined>;
formattedValue: Accessor<string | undefined>;
isDisabled: Accessor<boolean>;
Expand Down
32 changes: 27 additions & 5 deletions packages/core/src/time-field/time-field-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ export function TimeFieldField<T extends ValidComponent = "div">(
const { locale, direction } = useLocale();

const val = createMemo(
() => timeFieldContext.value() || timeFieldContext.placeholderValue(),
() => timeFieldContext.value() || timeFieldContext.placeholderTime(),
);

const [placeholderDate, setPlaceholderDate] = createSignal(
createPlaceholderDate(
val(),
timeFieldContext.placeholderValue(),
timeFieldContext.placeholderTime(),
timeFieldContext.defaultTimeZone(),
),
);
Expand Down Expand Up @@ -208,7 +208,11 @@ export function TimeFieldField<T extends ValidComponent = "div">(
const isPlaceholder =
isOriginallyEditable && !(validSegments() as any)[segment.type];
const placeholder = isOriginallyEditable
? getPlaceholder(segment.type, segment.value)
? getPlaceholder(
segment.type,
segment.value,
timeFieldContext.placeholderValue(),
)
: null;

return {
Expand Down Expand Up @@ -308,7 +312,7 @@ export function TimeFieldField<T extends ValidComponent = "div">(

const placeholder = createPlaceholderDate(
val(),
timeFieldContext.placeholderValue(),
timeFieldContext.placeholderTime(),
timeFieldContext.defaultTimeZone(),
);

Expand Down Expand Up @@ -557,10 +561,28 @@ function setSegmentBase(
}
}

export function getPlaceholder(field: string, value: string) {
export function getPlaceholder(
field: string,
value: string,
placeholderValue?: TimeValue,
) {
if (field === "dayPeriod") {
return value;
}

if (placeholderValue) {
if (placeholderValue.hour && field === "hour") {
return String(placeholderValue.hour);
}

if (placeholderValue.minute && field === "minute") {
return String(placeholderValue.minute);
}

if (placeholderValue.second && field === "second") {
return String(placeholderValue.second);
}
}

return "––";
}
3 changes: 2 additions & 1 deletion packages/core/src/time-field/time-field-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ export function TimeFieldRoot<T extends ValidComponent = "div">(
granularity,
hideTimeZone: () => local.hideTimeZone ?? false,
shouldForceLeadingZeros: () => local.shouldForceLeadingZeros ?? false,
placeholderValue: () => value() || (local.placeholderValue ?? new Time()),
placeholderTime: () => value() || (local.placeholderValue ?? new Time()),
placeholderValue: () => local.placeholderValue,
defaultTimeZone,
formattedValue,
focusManager: () => focusManager,
Expand Down

0 comments on commit 50941a9

Please sign in to comment.