Skip to content

Commit

Permalink
feat: update bottom sheet behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigosakamoto committed Sep 19, 2023
1 parent 3e0cf35 commit 8699a37
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/components/Select2/Select.tsx
Expand Up @@ -97,6 +97,7 @@ function Select<
useBottomSheet,
bottomSheetFooter,
bottomSheetHeader,
bottomSheetPlaceholder,
...props
}: Props<Option, IsMulti, Group> & CustomSelectProps) {
// only used for bottom sheet mode
Expand Down Expand Up @@ -226,13 +227,21 @@ function Select<
setMenuIsOpen(true);
props.onMenuOpen?.();
}}
onFocus={(e) => {
props.onFocus?.(e);

if (useBottomSheet) {
e.currentTarget.blur();
}
}}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
maxMenuHeight={useBottomSheet ? "100%" : 200}
label={label}
setMenuIsOpen={setMenuIsOpen}
bottomSheetHeader={bottomSheetHeader}
bottomSheetFooter={bottomSheetFooter}
bottomSheetPlaceholder={bottomSheetPlaceholder}
/>
{helper && (
<HelperDiv>
Expand Down
1 change: 1 addition & 0 deletions lib/components/Select2/Select.types.ts
Expand Up @@ -11,4 +11,5 @@ export interface CustomSelectProps {
useBottomSheet?: boolean;
bottomSheetFooter?: React.ReactNode;
bottomSheetHeader?: React.ReactNode;
bottomSheetPlaceholder?: string;
}
16 changes: 10 additions & 6 deletions lib/components/Select2/SelectBottomSheet.tsx
Expand Up @@ -22,7 +22,8 @@ export default function SelectBottomSheet(props: MenuProps) {

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { bottomSheetFooter, bottomSheetHeader } = props.selectProps;
const { bottomSheetFooter, bottomSheetHeader, bottomSheetPlaceholder } =
props.selectProps;

return (
<BottomSheet
Expand All @@ -38,12 +39,13 @@ export default function SelectBottomSheet(props: MenuProps) {
maxHeight * 0.9,
maxHeight,
]}
defaultSnap={({ maxHeight }) => maxHeight * 0.7}
defaultSnap={({ maxHeight }) => maxHeight * 0.9}
initialFocusRef={false}
header={
<>
<InputBox
type="text"
placeholder="Type Here"
placeholder={bottomSheetPlaceholder || "Type Here"}
startIcon={<BsSearch />}
spaceAfter="xxxbig"
value={inputValue}
Expand All @@ -54,9 +56,11 @@ export default function SelectBottomSheet(props: MenuProps) {
})
}
/>
<StyledText type="overlineLarge" color="neutral" shade="400">
{label}
</StyledText>
{label && (
<StyledText type="overlineLarge" color="neutral" shade="400">
{label}
</StyledText>
)}
{bottomSheetHeader}
</>
}
Expand Down
1 change: 1 addition & 0 deletions src/stories/components/select/Select.stories.tsx
Expand Up @@ -149,4 +149,5 @@ BottomSheetWithHeaderAndFooter.args = {
useBottomSheet: true,
bottomSheetHeader: <p>Header</p>,
bottomSheetFooter: <p>Footer</p>,
bottomSheetPlaceholder: "bottomSheetPlaceholder",
};

0 comments on commit 8699a37

Please sign in to comment.