Skip to content

Commit 8b2c51b

Browse files
authored
fix: Sort component icon & text ellipsis issue (#269)
1 parent 7b60d8b commit 8b2c51b

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/components/Sort/docs.stories.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useState } from 'react';
22

33
import { FaSortDown, FaSortUp } from 'react-icons/fa';
44

5+
import { Icon } from '@/components/Icons';
6+
57
import { Sort, SortValue } from '.';
68

79
export default {
@@ -50,15 +52,15 @@ export const CustomIcons = () => {
5052
sort={sortDesc}
5153
onChange={setSortDesc}
5254
options={options}
53-
ascIcon={FaSortUp}
54-
descIcon={FaSortDown}
55+
ascIcon={<Icon icon={FaSortUp} />}
56+
descIcon={<Icon icon={FaSortDown} />}
5557
/>
5658
<Sort
5759
sort={sortAsc}
5860
onChange={setSortAsc}
5961
options={options}
60-
ascIcon={FaSortUp}
61-
descIcon={FaSortDown}
62+
ascIcon={<Icon icon={FaSortUp} />}
63+
descIcon={<Icon icon={FaSortDown} />}
6264
/>
6365
</>
6466
);

src/components/Sort/index.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { FC } from 'react';
1+
import { FC, ReactNode } from 'react';
22

33
import {
4+
Box,
45
Button,
56
ButtonProps,
67
Menu,
@@ -31,8 +32,8 @@ type CustomProps = {
3132
size?: 'xs' | 'sm' | 'md';
3233
options?: Array<OptionProps>;
3334
onChange?(sort: SortValue): void;
34-
ascIcon?: FC<React.PropsWithChildren<unknown>>;
35-
descIcon?: FC<React.PropsWithChildren<unknown>>;
35+
ascIcon?: ReactNode;
36+
descIcon?: ReactNode;
3637
};
3738

3839
type SortProps = Overwrite<ButtonProps, CustomProps>;
@@ -42,16 +43,14 @@ export const Sort: FC<React.PropsWithChildren<SortProps>> = ({
4243
size = 'xs',
4344
options = [],
4445
onChange = () => undefined,
45-
ascIcon: AscIcon = IconSortAsc,
46-
descIcon: DescIcon = IconSortDesc,
46+
ascIcon = <IconSortAsc />,
47+
descIcon = <IconSortDesc />,
4748
...rest
4849
}) => {
4950
const { t } = useTranslation();
5051

5152
const { by, order } = sort;
5253

53-
const Icon = order === 'asc' ? AscIcon : DescIcon;
54-
5554
const handleByChange = (value: SortValue['by']) => {
5655
onChange({ ...sort, by: value });
5756
};
@@ -74,11 +73,19 @@ export const Sort: FC<React.PropsWithChildren<SortProps>> = ({
7473
_dark={{
7574
color: 'gray.100',
7675
}}
77-
sx={{ '> span': { d: 'flex', maxW: 'full' } }}
76+
sx={{ '> span': { display: 'flex', maxW: 'full' } }}
7877
{...rest}
7978
>
80-
<Icon mr="0.5" />
81-
<Text as="span" display="block" fontSize={size} noOfLines={1}>
79+
<Box as="span" mr="0.5">
80+
{order === 'asc' ? ascIcon : descIcon}
81+
</Box>
82+
<Text
83+
as="span"
84+
display="block"
85+
sx={{ '&': { display: 'block !important' } }} // Fix: text-ellipsis issue
86+
fontSize={size}
87+
noOfLines={1}
88+
>
8289
{options.find((option) => option?.value === by)?.label}
8390
</Text>
8491
</MenuButton>

0 commit comments

Comments
 (0)