Skip to content

Commit

Permalink
add default select for dropdown options (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
mazmassa authored May 29, 2023
1 parent 3107b6a commit 5baef1e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const _Dropdown = {
item: 'italiano',
},
]}
select={2}
/>
</div>

Expand Down
6 changes: 4 additions & 2 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { FiChevronDown, FiChevronUp } from 'react-icons/fi';
interface IOption extends ComponentPropsWithoutRef<'div'> {
icon?: JSX.Element;
item: string;
select?: number;
}

interface IDropdownProps extends ComponentPropsWithoutRef<'div'> {
options: IOption[];
size?: 'xs' | 'md';
select?: number;
}

function Icon({ toggle }: { toggle: boolean }) {
Expand All @@ -26,7 +28,7 @@ function Icon({ toggle }: { toggle: boolean }) {
}

export function Dropdown(props: IDropdownProps) {
let { size = 'md', options } = props;
let { size = 'md', select = 0, options } = props;

const classes = {
xs: {
Expand All @@ -43,7 +45,7 @@ export function Dropdown(props: IDropdownProps) {
},
};

const firstObject = options[0];
const firstObject = options[select];
const [toggle, setToggle] = useState(false);
const [selected, setSelected] = useState(firstObject);
const hidden = toggle ? '' : 'hidden';
Expand Down

0 comments on commit 5baef1e

Please sign in to comment.