diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/AutoFillDetector.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/AutoFillDetector.tsx index 7024fe665..cd0daf771 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/AutoFillDetector.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/AutoFillDetector.tsx @@ -10,17 +10,9 @@ export default function AutoFillDetector() { } = useFormContext() useEffect(() => { - const dirtyFieldKeys = Object.keys(dirtyFields) - const touchedFieldKeys = Object.keys(touchedFields) - const hasDirtyUnTouchedFields = dirtyFieldKeys.some( - (field) => !touchedFieldKeys.includes(field) - ) const subscription = watch((_, field) => { - if (!field.type) { - if (isDirty && hasDirtyUnTouchedFields) { - trigger(field.name) - trigger("countryCode") - } + if (field.name && dirtyFields[field.name] && !touchedFields[field.name]) { + trigger(field.name) } }) diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/index.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/index.tsx index 9297e35ac..b4d6fa9e9 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/index.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Details/RoomOne/index.tsx @@ -112,6 +112,7 @@ export default function Details({ user }: DetailsProps) { })} { - const collator = new Intl.Collator(lang) - return countries - .map((country) => ({ + function mapCountry(country: (typeof countries)[number]) { + return { value: country.code, label: intl.formatDisplayName(country.code, { type: "region" }) || country.name, - })) + } + } + + const collator = new Intl.Collator(lang) + const prioCountries = countries + .filter((c) => prioCountryCode.includes(c.code)) + .map(mapCountry) .filter((item) => startsWith(item.label, filterValue)) .sort((a, b) => collator.compare(a.label, b.label)) + + const restCountries = countries + .filter((c) => !prioCountryCode.includes(c.code)) + .map(mapCountry) + .filter((item) => startsWith(item.label, filterValue)) + .sort((a, b) => collator.compare(a.label, b.label)) + + return [...prioCountries, ...restCountries] }, [filterValue, intl, lang, startsWith]) + function handleOnInput(evt: SyntheticEvent) { + setFilterValue(evt.currentTarget.value) + const isAutoCompleteEvent = !("inputType" in evt.nativeEvent) + if (isAutoCompleteEvent) { + const { value } = evt.currentTarget + const cc = countries.find((c) => c.name === value || c.code === value) + if (cc) { + field.onChange(cc.code) + } + } + } + return (
- + +
+ + + + + {items.map((item) => ( + + {({ isSelected }) => ( + + {item.label} + + )} + + ))} + + + ) diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx index bb6c47fc5..d2dcb10db 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx @@ -19,6 +19,7 @@ import type { InputProps } from "./input" const Input = forwardRef(function Input( { "aria-label": ariaLabel, + autoComplete, className = "", disabled = false, helpText = "", @@ -65,6 +66,7 @@ const Input = forwardRef(function Input( {...field} ref={ref} aria-labelledby={field.name} + autoComplete={autoComplete} id={field.name} label={label} maxLength={maxLength} diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Phone/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Phone/index.tsx index ee724c08a..45b0fece8 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Phone/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Phone/index.tsx @@ -141,6 +141,7 @@ export default function Phone({ > undefined, onFocus = () => undefined, onBlur = () => undefined, + autoComplete, ...props }: SelectFilterProps) { const [focus, setFocus] = useState(false) @@ -73,7 +74,7 @@ export function SelectFilter({ {label} - +