Skip to content

Commit

Permalink
feat: navigate to select's value (#152)
Browse files Browse the repository at this point in the history
Co-authored-by: GetPsyched <[email protected]>
  • Loading branch information
heydoyouknowme0 and GetPsyched authored Apr 25, 2024
1 parent b29227a commit 2b2c056
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 1 addition & 4 deletions app/[locale]/profile/client-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ export const Tabs = ({
];

return select ? (
<Select
onValueChange={(value) => router.push(`/${locale}/profile/${value}`)}
defaultValue={tab}
>
<Select defaultValue={tab} navigate>
<SelectTrigger className="w-[180px] px-4 py-5 text-shade-light md:hidden">
<SelectValue />
</SelectTrigger>
Expand Down
14 changes: 13 additions & 1 deletion components/inputs/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as SelectPrimitive from '@radix-ui/react-select';
import { cva } from 'class-variance-authority';
import { useRouter } from 'next/navigation';
import * as React from 'react';
import { RxCheck, RxChevronDown, RxChevronUp } from 'react-icons/rx';

Expand All @@ -24,14 +25,25 @@ function useSelect() {
}

const Select = ({
navigate = false,
onValueChange,
variant = 'ui',
...props
}: React.ComponentPropsWithoutRef<typeof SelectPrimitive.Root> & {
navigate?: boolean;
variant?: 'form' | 'ui';
}) => {
const router = useRouter();

return (
<SelectContext.Provider value={{ variant }}>
<SelectPrimitive.Root {...props} />
<SelectPrimitive.Root
onValueChange={(value) => {
navigate && router.push(value);
onValueChange && onValueChange(value);
}}
{...props}
/>
</SelectContext.Provider>
);
};
Expand Down

0 comments on commit 2b2c056

Please sign in to comment.