Skip to content

Commit f85ba6d

Browse files
fix: sd-select dropdown resizing (#2749)
## Description: Closes: https://github.com/orgs/solid-design-system/projects/1/views/68?pane=issue&itemId=145154220&issue=solid-design-system%7Csolid%7C2660 Previously this PR: #2666 Fixed the issue with the sd-select not resizing properly. The option drop down was also changed to wrap the words to the next line. The tags when inside the sd-select are also now handled and three points are added when the word is too big. Example: <img width="252" height="563" alt="image" src="https://github.com/user-attachments/assets/2211bf7a-b424-4aa2-abc3-f3221907a3ba" /> ## Definition of Reviewable: - [X] relevant tickets are linked --------- Co-authored-by: Sérgio Fonseca <42741644+smfonseca@users.noreply.github.com>
1 parent 7e3a861 commit f85ba6d

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

.changeset/crisp-groups-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@solid-design-system/components': minor
3+
---
4+
5+
Fixed the resizing of the `sd-select`, including the way the `sd-option` and `sd-tag` resize inside this component

packages/components/src/components/option/option.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ export default class SdOption extends SolidElement {
137137
return html`
138138
<div
139139
part="base"
140+
style="word-break: break-word;"
140141
class=${cx(
141-
'px-4 flex items-center w-full transition-colors duration-fast ease-in-out text-left text-base relative',
142+
'px-4 flex items-start w-full transition-colors duration-fast ease-in-out text-left text-base relative',
142143
{
143144
sm: 'text-sm py-1',
144145
md: 'text-base py-2',
@@ -166,6 +167,11 @@ export default class SdOption extends SolidElement {
166167
part="control ${this.selected ? ' control--checked' : 'control--unchecked'}"
167168
class=${cx(
168169
'relative flex flex-shrink-0 items-center justify-center border rounded-sm h-4 w-4 mr-2',
170+
{
171+
sm: 'mt-0.5',
172+
md: 'mt-1',
173+
lg: 'mt-1'
174+
}[this.size],
169175
this.disabled
170176
? 'sd-option--disabled-color-border'
171177
: this.selected

packages/components/src/components/select/select.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
207207
@property() getTag: (option: SdOption, index: number) => TemplateResult | string | HTMLElement = option => {
208208
return html`
209209
<sd-tag
210-
class="relative z-10"
210+
class="relative z-10 min-w-0 max-w-full"
211211
?disabled=${this.disabled}
212212
part="tag"
213213
exportparts="
@@ -693,7 +693,7 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
693693
if (index < this.maxOptionsVisible || this.maxOptionsVisible <= 0) {
694694
const tag = this.getTag(option, index);
695695
// Wrap so we can handle the remove
696-
return html` <div @sd-remove=${(e: CustomEvent) => this.handleTagRemove(e, option)}>
696+
return html` <div @sd-remove=${(e: CustomEvent) => this.handleTagRemove(e, option)} class="max-w-full">
697697
${typeof tag === 'string' ? unsafeHTML(tag) : tag}
698698
</div>`;
699699
}
@@ -703,7 +703,7 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
703703
return [
704704
html`
705705
<sd-tag
706-
class="z-10"
706+
class="z-10 min-w-0 max-w-full"
707707
?disabled=${this.disabled}
708708
part="tag"
709709
exportparts="
@@ -1047,7 +1047,7 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
10471047
>
10481048
<div
10491049
class=${cx(
1050-
'input-container items-center w-full h-full px-4 flex',
1050+
'input-container items-center w-full h-full px-4 flex min-w-0',
10511051
{
10521052
sm: 'py-1',
10531053
md: 'py-1',
@@ -1061,7 +1061,7 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
10611061
form=${this.form}
10621062
part="display-input"
10631063
class=${cx(
1064-
'top-0 left-0 appearance-none outline-none flex-grow bg-transparent flex-1 placeholder:text-neutral-700',
1064+
'top-0 left-0 appearance-none outline-none flex-grow bg-transparent flex-1 placeholder:text-neutral-700 min-w-0',
10651065
cursorStyles,
10661066
this.multiple && this.useTags && this.value.length > 0 ? 'hidden' : '',
10671067
this.size === 'sm'
@@ -1094,10 +1094,10 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
10941094
tabindex="-1"
10951095
/>
10961096
1097-
${this.multiple && this.useTags
1097+
${this.multiple && this.useTags && this.tags && this.tags.length > 0
10981098
? html` <div
10991099
part="tags"
1100-
class=${cx('flex-grow flex flex-wrap items-center gap-1', this.floatingLabel && 'pt-6')}
1100+
class=${cx('flex-grow flex flex-wrap items-center gap-1 min-w-0', this.floatingLabel && 'pt-6')}
11011101
>
11021102
${this.tags}
11031103
</div>`
@@ -1126,7 +1126,7 @@ export default class SdSelect extends SolidElement implements SolidFormControl {
11261126
class=${cx(
11271127
'select__clear flex justify-center',
11281128
iconMarginLeft,
1129-
this.value.length > 0 ? 'visible' : 'invisible'
1129+
this.value.length > 0 ? 'visible' : 'hidden'
11301130
)}
11311131
type="button"
11321132
aria-label=${this.localize.term('clearEntry')}

packages/components/src/components/tag/tag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export default class SdTag extends SolidElement {
143143
@focus=${this.handleFocus}
144144
class=${cx(
145145
/* basic styles of the wrapper */
146-
'inline-flex border box-border sd-tag-border-radius items-center leading-none whitespace-nowrap transition-colors duration-fast ease-in-out focus-visible:focus-outline',
146+
'flex border box-border sd-tag-border-radius items-center leading-none whitespace-nowrap transition-colors duration-fast ease-in-out focus-visible:focus-outline',
147147
{
148148
/* sizes, fonts */
149149
lg: 'h-8 sd-tag-font-weight sd-tag--size-lg-font-size gap-2',

packages/docs/src/stories/components/select.test.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export const ValidInvalid = {
209209
return html`<form class="h-[260px] w-full flex gap-4">
210210
${generateTemplate({
211211
options: {
212-
classes: 'w-full [&>tbody>tr>td]:align-top'
212+
classes: 'w-full [&>tbody>tr>td]:align-top [&>tbody>tr>td]:w-[50%]'
213213
},
214214
axis: {
215215
y: {

0 commit comments

Comments
 (0)