Skip to content

Commit

Permalink
CustomSelectControlV2: Handle long strings in selected value
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed May 31, 2024
1 parent b89fb7b commit 65e3a00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const CustomSelectButton = ( {
// move selection rather than open the popover
showOnKeyDown={ false }
>
<div>{ computedRenderSelectedValue( currentValue ) }</div>
{ computedRenderSelectedValue( currentValue ) }
</Styled.Select>
);
};
Expand Down
30 changes: 20 additions & 10 deletions packages/components/src/custom-select-control-v2/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import styled from '@emotion/styled';
*/
import { COLORS, CONFIG } from '../utils';
import { space } from '../utils/space';
import { chevronIconSize } from '../select-control/styles/select-control-styles';
import type { CustomSelectButtonSize } from './types';

const ITEM_PADDING = space( 2 );
Expand Down Expand Up @@ -55,40 +56,49 @@ export const Select = styled( Ariakit.Select, {
const sizes = {
compact: {
[ heightProperty ]: 32,
paddingInlineStart: space( 2 ),
paddingInlineEnd: space( 1 ),
paddingInlineStart: 8,
paddingInlineEnd: 8 + chevronIconSize,
},
default: {
[ heightProperty ]: 40,
paddingInlineStart: space( 4 ),
paddingInlineEnd: space( 3 ),
paddingInlineStart: 16,
paddingInlineEnd: 16 + chevronIconSize,
},
small: {
[ heightProperty ]: 24,
paddingInlineStart: space( 2 ),
paddingInlineEnd: space( 1 ),
fontSize: 11,
paddingInlineStart: 8,
paddingInlineEnd: 8 + chevronIconSize,
},
};

return sizes[ size ] || sizes.default;
};

const truncateStyles =
! hasCustomRenderProp &&
css`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;

return css`
display: flex;
align-items: center;
justify-content: space-between;
display: block;
background-color: ${ COLORS.theme.background };
border: none;
color: ${ COLORS.theme.foreground };
cursor: pointer;
font-family: inherit;
font-size: ${ CONFIG.fontSize };
text-align: left;
width: 100%;
&[data-focus-visible] {
outline: none; // handled by InputBase component
}
${ getSize() }
${ truncateStyles }
`;
} );

Expand Down

0 comments on commit 65e3a00

Please sign in to comment.