From a1c56d29d0c63521c00e3a54beffd7041023f430 Mon Sep 17 00:00:00 2001 From: Patel Aryan Saurabhkumar <110459548+patelaryan0914@users.noreply.github.com> Date: Fri, 10 Oct 2025 19:52:51 +0530 Subject: [PATCH] fix(dashboard): replace native select Element in CountrySelect & ProvinceSelect with Select(Medusa UI). (#13521) * fix: replace CountrySelect fallback with Medusa Select * Country Select Component Fix to use Medusa UI Select Component * added Change set * using the props supported by the Select * value should be lowercased if passed from the pareant component * fix province Select with medusa UI select and added change set * bug fix the province with providing --------- Co-authored-by: Aryan Patel <21cs038@charusat.edu.in> Co-authored-by: William Bouchard <46496014+willbouch@users.noreply.github.com> --- .changeset/four-kings-drive.md | 5 + .../inputs/country-select/country-select.tsx | 99 +++++++---------- .../province-select/province-select.tsx | 104 +++++++----------- .../edit-location-form/edit-location-form.tsx | 3 +- 4 files changed, 85 insertions(+), 126 deletions(-) create mode 100644 .changeset/four-kings-drive.md diff --git a/.changeset/four-kings-drive.md b/.changeset/four-kings-drive.md new file mode 100644 index 0000000000..f278c7438f --- /dev/null +++ b/.changeset/four-kings-drive.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +fix(dashboard):replace native select Element in CountrySelect & ProvinceSelect with Select(Medusa UI). diff --git a/packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx b/packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx index 7ccec4e0ce..07d8904c0c 100644 --- a/packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx +++ b/packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx @@ -4,75 +4,50 @@ import { useImperativeHandle, useRef, } from "react" - -import { TrianglesMini } from "@medusajs/icons" -import { clx } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { countries } from "../../../lib/data/countries" +import { Select } from "@medusajs/ui" export const CountrySelect = forwardRef< - HTMLSelectElement, - ComponentPropsWithoutRef<"select"> & { + HTMLButtonElement, + ComponentPropsWithoutRef & { placeholder?: string - value?: string defaultValue?: string + onChange?: (value: string) => void } ->( - ( - { className, disabled, placeholder, value, defaultValue, ...props }, - ref - ) => { - const { t } = useTranslation() - const innerRef = useRef(null) +>(({ disabled, placeholder, defaultValue, onChange, ...field }, ref) => { + const { t } = useTranslation() + const innerRef = useRef(null) - useImperativeHandle(ref, () => innerRef.current as HTMLSelectElement) + useImperativeHandle(ref, () => innerRef.current as HTMLButtonElement) + + return ( +
+ +
+ ) +}) - const isPlaceholder = innerRef.current?.value === "" - - return ( -
- - -
- ) - } -) CountrySelect.displayName = "CountrySelect" diff --git a/packages/admin/dashboard/src/components/inputs/province-select/province-select.tsx b/packages/admin/dashboard/src/components/inputs/province-select/province-select.tsx index 6813b44816..d1c60d95ec 100644 --- a/packages/admin/dashboard/src/components/inputs/province-select/province-select.tsx +++ b/packages/admin/dashboard/src/components/inputs/province-select/province-select.tsx @@ -4,47 +4,36 @@ import { useImperativeHandle, useRef, } from "react" - -import { TrianglesMini } from "@medusajs/icons" -import { clx } from "@medusajs/ui" +import { Select } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { getCountryProvinceObjectByIso2 } from "../../../lib/data/country-states" -interface ProvinceSelectProps extends ComponentPropsWithoutRef<"select"> { - /** - * ISO 3166-1 alpha-2 country code - */ - country_code: string - /** - * Whether to use the ISO 3166-1 alpha-2 code or the name of the province as the value - * - * @default "iso_2" - */ - valueAs?: "iso_2" | "name" - placeholder?: string -} - export const ProvinceSelect = forwardRef< - HTMLSelectElement, - ProvinceSelectProps + HTMLButtonElement, + ComponentPropsWithoutRef & { + placeholder?: string + defaultValue?: string + country_code: string + valueAs?: "iso_2" | "name" + onChange?: (value: string) => void + } >( ( { - className, disabled, placeholder, + defaultValue, country_code, valueAs = "iso_2", - ...props + onChange, + ...field }, ref ) => { const { t } = useTranslation() - const innerRef = useRef(null) + const innerRef = useRef(null) - useImperativeHandle(ref, () => innerRef.current as HTMLSelectElement) - - const isPlaceholder = innerRef.current?.value === "" + useImperativeHandle(ref, () => innerRef.current as HTMLButtonElement) const provinceObject = getCountryProvinceObjectByIso2(country_code) @@ -55,9 +44,12 @@ export const ProvinceSelect = forwardRef< const options = Object.entries(provinceObject?.options ?? {}).map( ([iso2, name]) => { return ( - + ) } ) @@ -66,46 +58,34 @@ export const ProvinceSelect = forwardRef< ? t(`taxRegions.fields.sublevels.placeholders.${provinceObject.type}`) : "" - const placeholderOption = provinceObject ? ( - - ) : null - return (
- - + + + + {options} +
) } ) -ProvinceSelect.displayName = "CountrySelect" +ProvinceSelect.displayName = "ProvinceSelect" diff --git a/packages/admin/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx b/packages/admin/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx index 26bb8ba9b6..291cb310e7 100644 --- a/packages/admin/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx +++ b/packages/admin/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx @@ -4,12 +4,11 @@ import { Button, Input, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import * as zod from "zod" - import { Form } from "../../../../../components/common/form" -import { CountrySelect } from "../../../../../components/inputs/country-select" import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { KeyboundForm } from "../../../../../components/utilities/keybound-form" import { useUpdateStockLocation } from "../../../../../hooks/api/stock-locations" +import { CountrySelect } from "../../../../../components/inputs/country-select/country-select" type EditLocationFormProps = { location: HttpTypes.AdminStockLocation