Skip to content

Commit c58b3bf

Browse files
authored
fix(combobox): placeholder cropping in Multiselect Combobox (#3540)
* fix(combobox): placeholder cropping in multiselect * fix: only show placeholder when there are no selectedItems
1 parent 1a70ec0 commit c58b3bf

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

.changeset/sour-knives-design.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@twilio-paste/combobox": patch
3+
"@twilio-paste/core": patch
4+
---
5+
6+
[Combobox] Fix `placeholder` cropping issue in MultiselectCombobox

packages/paste-core/components/combobox/src/multiselect/GrowingInput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ interface GrowingInputProps {
99
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
1010
id: string;
1111
value?: HTMLInputElement["value"];
12+
placeholder?: string;
1213
}
1314

1415
export const GrowingInput = React.forwardRef<HTMLInputElement, GrowingInputProps>(
15-
({ element = "GROWING_INPUT", onChange, initialValue = "", value, ...props }, ref) => {
16+
({ element = "GROWING_INPUT", onChange, initialValue = "", value, placeholder = "", ...props }, ref) => {
1617
const [text, setText] = React.useState(value || initialValue);
1718

1819
React.useEffect(() => {
@@ -42,7 +43,7 @@ export const GrowingInput = React.forwardRef<HTMLInputElement, GrowingInputProps
4243
height="28px"
4344
alignContent="center"
4445
_after={{
45-
content: `"${text}"`,
46+
content: `"${text || placeholder || ""}"`,
4647
fontFamily: "inherit",
4748
fontSize: "fontSize30",
4849
fontWeight: "fontWeightMedium",
@@ -58,6 +59,7 @@ export const GrowingInput = React.forwardRef<HTMLInputElement, GrowingInputProps
5859
element={element}
5960
type="text"
6061
value={value != null ? value.replace(/ +/g, " ") : text}
62+
placeholder={placeholder}
6163
padding="space0"
6264
onChange={(event) => {
6365
event.preventDefault();

packages/paste-core/components/combobox/src/multiselect/MultiselectCombobox.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const MultiselectCombobox = React.forwardRef<HTMLInputElement, Multiselec
3232
initialSelectedItems = [],
3333
disabledItems,
3434
inputValue,
35+
placeholder,
3536
insertAfter,
3637
insertBefore,
3738
items,
@@ -355,6 +356,7 @@ export const MultiselectCombobox = React.forwardRef<HTMLInputElement, Multiselec
355356
disabled,
356357
onKeyDown: handleKeyDown,
357358
})}
359+
placeholder={selectedItems.length === 0 ? placeholder : ""}
358360
aria-describedby={helpTextId}
359361
element={`${element}_ELEMENT`}
360362
/>

packages/paste-core/components/combobox/stories/GrowingInput.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const GrowingInputDemo: StoryFn = () => {
1414
<Label htmlFor={id}>Type in here:</Label>
1515
<Box display="flex" alignItems="center">
1616
<span> -&gt; </span>
17-
<GrowingInput id={id} />
17+
<GrowingInput id={id} placeholder="Long placeholder text with extra long spaces ." />
1818
<span> &lt;- </span>
1919
</Box>
2020
</>

packages/paste-core/components/combobox/stories/MultiselectCombobox.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const BottomOfScreen = (): React.ReactNode => {
7777
labelText="Choose a Paste Component"
7878
selectedItemsLabelText="Selected Paste components"
7979
helpText="Paste components are the building blocks of your product UI."
80+
placeholder="Search by SID or name"
8081
items={filteredItems}
8182
onInputValueChange={({ inputValue: newInputValue = "" }) => {
8283
setInputValue(newInputValue);

0 commit comments

Comments
 (0)