Skip to content

Commit

Permalink
fix: dropdown item too long
Browse files Browse the repository at this point in the history
  • Loading branch information
steven11329 committed Nov 15, 2023
1 parent cbd7b23 commit c509da7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beeinventor/dasiot-react-component-lib",
"version": "1.8.3",
"version": "1.8.4",
"module": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
Expand Down
29 changes: 29 additions & 0 deletions src/components/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const list: DropDownItem[] = [
value: 'A004',
name: 'Distributor C',
},
{
id: 'A004',
value: 'A004',
name: 'Very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long',
},
];

const meta: Meta<typeof Dropdown> = {
Expand Down Expand Up @@ -64,6 +69,30 @@ export const Default: Story = {
render: () => <Dropdown list={list} onSelect={() => {}} />,
};

export const FixItemTooLong: Story = {
render: () => (
<Dropdown
list={list}
onSelect={() => {}}
popperProps={{
sx: {
'& .Dropdown-icon': {
flexShrink: 0,
},
'& .Dropdown-item': {
'> span': {
minWidth: 0,
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
},
},
},
}}
/>
),
};

export const Exceptance: Story = {
render: () => (
<Dropdown
Expand Down
16 changes: 14 additions & 2 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ const Root = styled(Box)(({ theme }) => ({
opacity: 0.3,
pointerEvents: 'none',
},

'& .selected-name': {
minWidth: 0,
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
},
}));

const List = styled(Box)(({ theme }) => ({
Expand Down Expand Up @@ -148,7 +155,7 @@ const Dropdown: React.FC<DropDownProps> = (props) => {
<Icon className="Dropdown-icon">
{selectedItem?.id === item.id && <img src={CheckSvg} />}
</Icon>
{item.name}
<span title={item.name}>{item.name}</span>
</Item>
));

Expand All @@ -172,7 +179,12 @@ const Dropdown: React.FC<DropDownProps> = (props) => {
onClick={handleOnClickSelect}
{...otherProps}
>
{selectedItem?.name ?? placeholder}
<span
className="selected-name"
title={selectedItem?.name ?? placeholder}
>
{selectedItem?.name ?? placeholder}
</span>
<Icon className="Dropdown-icon">
{isOpen ? <KeyboardArrowUp /> : <KeyboardArrowDown />}
</Icon>
Expand Down

0 comments on commit c509da7

Please sign in to comment.