Skip to content

Commit

Permalink
Provide refs to make inputs focus when clicking preview, and update t…
Browse files Browse the repository at this point in the history
…ype to match mui 6 components.
  • Loading branch information
ziggabyte committed Sep 12, 2023
1 parent ae0ae5d commit 58af978
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/features/events/components/EventOverviewCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ const EventOverviewCard: FC<EventOverviewCardProps> = ({
<Box flex={1}>
<ZUIPreviewableInput
{...previewableProps}
renderInput={() => {
renderInput={(params) => {
params.ref;
return (
<DatePicker
format="DD-MM-YYYY"
inputRef={params.ref}
label={messages.eventOverviewCard.startDate()}
onChange={(newStartDate) => {
if (newStartDate) {
Expand Down Expand Up @@ -161,12 +163,13 @@ const EventOverviewCard: FC<EventOverviewCardProps> = ({
/>
<ZUIPreviewableInput
{...previewableProps}
renderInput={() => {
renderInput={(params) => {
return (
<TimeField
ampm={false}
format="HH:mm"
fullWidth
inputRef={params.ref}
label={messages.eventOverviewCard.startTime()}
onChange={(newStartTime) => {
if (newStartTime) {
Expand Down Expand Up @@ -201,7 +204,7 @@ const EventOverviewCard: FC<EventOverviewCardProps> = ({
>
<ZUIPreviewableInput
{...previewableProps}
renderInput={() => {
renderInput={(params) => {
return (
<>
{!showEndDate && (
Expand All @@ -219,6 +222,7 @@ const EventOverviewCard: FC<EventOverviewCardProps> = ({
{showEndDate && (
<DatePicker
format="DD-MM-YYYY"
inputRef={params.ref}
label={messages.eventOverviewCard.endDate()}
minDate={dayjs(startDate)}
onChange={(newEndDate) => {
Expand Down Expand Up @@ -256,13 +260,14 @@ const EventOverviewCard: FC<EventOverviewCardProps> = ({
/>
<ZUIPreviewableInput
{...previewableProps}
renderInput={() => {
renderInput={(params) => {
return (
<TimeField
ampm={false}
disableIgnoringDatePartForTimeValidation={true}
format="HH:mm"
fullWidth
inputRef={params.ref}
label={messages.eventOverviewCard.endTime()}
minTime={dayjs(naiveStart).add(1, 'min')}
onChange={(newEndTime) => {
Expand Down
6 changes: 3 additions & 3 deletions src/zui/ZUIPreviewableInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box } from '@mui/material';
import { HTMLProps, useEffect, useRef } from 'react';
import { Ref, useEffect, useRef } from 'react';

export enum ZUIPreviewableMode {
EDITABLE = 'editable',
Expand All @@ -10,14 +10,14 @@ type ZUIPreviewableInputProps<ValueType, InputType> = {
focusInitially?: boolean;
mode: ZUIPreviewableMode;
onSwitchMode?: (mode: ZUIPreviewableMode) => void;
renderInput: (props: HTMLProps<InputType>) => JSX.Element;
renderInput: (props: { ref: Ref<InputType> }) => JSX.Element;
renderPreview?: () => JSX.Element;
value: ValueType;
};

function ZUIPreviewableInput<
ValueType extends string | number,
InputType extends HTMLElement
InputType extends HTMLInputElement
>({
focusInitially = false,
mode,
Expand Down

0 comments on commit 58af978

Please sign in to comment.