Skip to content

Commit 85c9a79

Browse files
authored
fix: prevent location input from losing focus after each key stroke (calcom#22167)
* fix: prevent location input from losing focus after each key stroke * typo
1 parent e17d554 commit 85c9a79

1 file changed

Lines changed: 61 additions & 58 deletions

File tree

packages/features/eventtypes/components/Locations.tsx

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,66 @@ const getLocationInfo = ({
107107
return { locationAvailable, locationDetails };
108108
};
109109

110+
const LocationInput = (props: {
111+
eventLocationType: EventLocationType;
112+
defaultValue?: string;
113+
index: number;
114+
customClassNames?: LocationInputCustomClassNames;
115+
disableLocationProp?: boolean;
116+
}) => {
117+
const { t } = useLocale();
118+
const { eventLocationType, index, customClassNames, disableLocationProp, ...remainingProps } = props;
119+
if (eventLocationType?.organizerInputType === "text") {
120+
const { defaultValue, ...rest } = remainingProps;
121+
122+
return (
123+
<Controller
124+
name={`locations.${index}.${eventLocationType.defaultValueVariable}`}
125+
defaultValue={defaultValue}
126+
render={({ field: { onChange, value } }) => {
127+
return (
128+
<Input
129+
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
130+
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
131+
type="text"
132+
required
133+
onChange={onChange}
134+
value={value}
135+
{...(disableLocationProp ? { disabled: true } : {})}
136+
className={classNames("my-0", customClassNames?.addressInput)}
137+
{...rest}
138+
/>
139+
);
140+
}}
141+
/>
142+
);
143+
} else if (eventLocationType?.organizerInputType === "phone") {
144+
const { defaultValue, ...rest } = remainingProps;
145+
146+
return (
147+
<Controller
148+
name={`locations.${index}.${eventLocationType.defaultValueVariable}`}
149+
defaultValue={defaultValue}
150+
render={({ field: { onChange, value } }) => {
151+
return (
152+
<PhoneInput
153+
required
154+
disabled={disableLocationProp}
155+
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
156+
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
157+
className={customClassNames?.phoneInput}
158+
value={value}
159+
onChange={onChange}
160+
{...rest}
161+
/>
162+
);
163+
}}
164+
/>
165+
);
166+
}
167+
return null;
168+
};
169+
110170
const Locations: React.FC<LocationsProps> = ({
111171
isChildrenManagedEventType,
112172
disableLocationProp,
@@ -168,64 +228,6 @@ const Locations: React.FC<LocationsProps> = ({
168228
locationOptions: props.locationOptions,
169229
});
170230

171-
const LocationInput = (props: {
172-
eventLocationType: EventLocationType;
173-
defaultValue?: string;
174-
index: number;
175-
customClassNames?: LocationInputCustomClassNames;
176-
}) => {
177-
const { eventLocationType, index, customClassNames, ...remainingProps } = props;
178-
if (eventLocationType?.organizerInputType === "text") {
179-
const { defaultValue, ...rest } = remainingProps;
180-
181-
return (
182-
<Controller
183-
name={`locations.${index}.${eventLocationType.defaultValueVariable}`}
184-
defaultValue={defaultValue}
185-
render={({ field: { onChange, value } }) => {
186-
return (
187-
<Input
188-
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
189-
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
190-
type="text"
191-
required
192-
onChange={onChange}
193-
value={value}
194-
{...(disableLocationProp ? { disabled: true } : {})}
195-
className={classNames("my-0", customClassNames?.addressInput)}
196-
{...rest}
197-
/>
198-
);
199-
}}
200-
/>
201-
);
202-
} else if (eventLocationType?.organizerInputType === "phone") {
203-
const { defaultValue, ...rest } = remainingProps;
204-
205-
return (
206-
<Controller
207-
name={`locations.${index}.${eventLocationType.defaultValueVariable}`}
208-
defaultValue={defaultValue}
209-
render={({ field: { onChange, value } }) => {
210-
return (
211-
<PhoneInput
212-
required
213-
disabled={disableLocationProp}
214-
placeholder={t(eventLocationType.organizerInputPlaceholder || "")}
215-
name={`locations[${index}].${eventLocationType.defaultValueVariable}`}
216-
className={customClassNames?.phoneInput}
217-
value={value}
218-
onChange={onChange}
219-
{...rest}
220-
/>
221-
);
222-
}}
223-
/>
224-
);
225-
}
226-
return null;
227-
};
228-
229231
const [showEmptyLocationSelect, setShowEmptyLocationSelect] = useState(false);
230232
const defaultInitialLocation = defaultValue || null;
231233
const [selectedNewOption, setSelectedNewOption] = useState<SingleValueLocationOption | null>(
@@ -459,6 +461,7 @@ const Locations: React.FC<LocationsProps> = ({
459461
eventLocationType={eventLocationType}
460462
index={index}
461463
customClassNames={customClassNames?.organizerContactInput?.locationInput}
464+
disableLocationProp={disableLocationProp}
462465
/>
463466
</div>
464467
<ErrorMessage

0 commit comments

Comments
 (0)