-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CustomSelectControlV2: Handle long strings in selected value #62198
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,12 +90,12 @@ function CustomSelectControl( props: LegacyCustomSelectProps ) { | |
); | ||
|
||
return ( | ||
<> | ||
<Styled.SelectedExperimentalHintWrapper> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a wrapper div to apply text truncation styles as in v1. |
||
{ currentValue } | ||
<Styled.SelectedExperimentalHintItem className="components-custom-select-control__hint"> | ||
{ currentHint?.__experimentalHint } | ||
</Styled.SelectedExperimentalHintItem> | ||
</> | ||
</Styled.SelectedExperimentalHintWrapper> | ||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,27 @@ 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 ); | ||
|
||
const truncateStyles = css` | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
`; | ||
|
||
export const WithHintWrapper = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
flex: 1; | ||
`; | ||
|
||
export const SelectedExperimentalHintWrapper = styled.div` | ||
${ truncateStyles } | ||
`; | ||
|
||
export const SelectedExperimentalHintItem = styled.span` | ||
color: ${ COLORS.theme.gray[ 600 ] }; | ||
margin-inline-start: ${ space( 2 ) }; | ||
|
@@ -55,40 +66,41 @@ export const Select = styled( Ariakit.Select, { | |
const sizes = { | ||
compact: { | ||
[ heightProperty ]: 32, | ||
paddingInlineStart: space( 2 ), | ||
paddingInlineEnd: space( 1 ), | ||
paddingInlineStart: 8, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good reason to stop using the grid space util and hardcode the padding widths like that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious about that, too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No big reason other than that I thought it was simpler to read in context, especially when I want to add the |
||
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; | ||
}; | ||
|
||
return css` | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
Comment on lines
-78
to
-80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason for this to be a flexbox. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Knowing past Marco, there's a chance flexbox was used to automatically trim extra white space (although it's also very possible that this is a remnant of a previous style and it's totally fine to remove it) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably totally fine to remove it :D |
||
display: block; | ||
background-color: ${ COLORS.theme.background }; | ||
border: none; | ||
color: ${ COLORS.theme.foreground }; | ||
cursor: pointer; | ||
font-family: inherit; | ||
Comment on lines
+91
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct |
||
font-size: ${ CONFIG.fontSize }; | ||
text-align: left; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Text align was missing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch 👍 I wonder how this didn't come up earlier. |
||
width: 100%; | ||
|
||
&[data-focus-visible] { | ||
outline: none; // handled by InputBase component | ||
} | ||
|
||
${ getSize() } | ||
${ ! hasCustomRenderProp && truncateStyles } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't add truncate styles when the consumer passes a custom render function. |
||
`; | ||
} ); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
div
is unnecessary.