Skip to content

Commit

Permalink
Document listboxOverflow Select prop
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Oct 28, 2024
1 parent 470e1e7 commit b9758df
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/components/input/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,24 +440,13 @@ type BaseSelectProps = CompositeProps & {
/**
* Indicates how overflowing content should be handled in the listbox.
*
<<<<<<< HEAD
* - `truncate`: Truncate the options via `text-overflow: ellipsis`, so that
* they all fit in one line. This is the default value.
* - `wrap`: Let options content wrap onto multiple lines via
* `white-space: normal`
*
* Complex content may still need to provide its own styling to handle content
* overflow.
=======
* - `truncate`: Truncate the options so that they all fit in one line. An
* ellipsis will be rendered where needed.
* This is the default value.
* - `wrap`: Let options content wrap multiple lines so that all content is
* visible.
*
* This behavior can be also overwritten by providing more complex options
* content.
>>>>>>> 51ceff5 (Prevent Select listbox to grow out of viewport)
*/
listboxOverflow?: ListboxOverflow;
};
Expand Down
34 changes: 34 additions & 0 deletions src/pattern-library/components/patterns/prototype/SelectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,40 @@ export default function SelectPage() {
</Library.InfoItem>
</Library.Info>
</Library.Example>
<Library.Example title="listboxOverflow">
<Library.Info>
<Library.InfoItem label="description">
Determines the behavior of the listbox options when their
content is larger than the listbox.
<ul className="list-disc">
<li>
<code>{"'truncate'"}</code>: Text will use one line and be
truncated with an ellipsis.
</li>
<li>
<code>{"'wrap'"}</code>: Text will span multiple lines if
needed, ensuring all content is visible.
</li>
</ul>
</Library.InfoItem>
<Library.InfoItem label="type">
<code>{"'truncate' | 'wrap'"}</code>
</Library.InfoItem>
<Library.InfoItem label="default">
<code>{"'truncate'"}</code>
</Library.InfoItem>
</Library.Info>
<Library.Demo
title="Truncate listbox options"
exampleFile="select-truncate-listbox"
withSource
/>
<Library.Demo
title="Wrap listbox options"
exampleFile="select-wrap-listbox"
withSource
/>
</Library.Example>
</Library.Pattern>

<Library.Pattern title="Select.Option component API">
Expand Down
51 changes: 51 additions & 0 deletions src/pattern-library/examples/select-truncate-listbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useId, useState } from 'preact/hooks';

import { Select } from '../..';

const items = [
{
id: '1',
name: 'All students - content is very long and will not fit the listbox',
},
{
id: '2',
name: 'Albert Banana - content is very long and will not fit the listbox',
},
{
id: '3',
name: 'Bernard California - content is very long and will not fit the listbox',
},
{
id: '4',
name: 'Cecelia Davenport - content is very long and will not fit the listbox',
},
{
id: '5',
name: 'Doris Evanescence - content is very long and will not fit the listbox',
},
];

export default function App() {
const [value, setSelected] = useState<{ id: string; name: string }>();
const selectId = useId();

return (
<div className="w-96 mx-auto">
<label htmlFor={selectId}>Select a person</label>
<Select
value={value}
onChange={newValue => setSelected(newValue)}
buttonId={selectId}
buttonContent={value ? value.name : <>Select one…</>}
listboxClasses="w-36"
listboxOverflow="truncate"
>
{items.map(item => (
<Select.Option value={item} key={item.id}>
{item.name}
</Select.Option>
))}
</Select>
</div>
);
}
51 changes: 51 additions & 0 deletions src/pattern-library/examples/select-wrap-listbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useId, useState } from 'preact/hooks';

import { Select } from '../..';

const items = [
{
id: '1',
name: 'All students - content is very long and will not fit the listbox',
},
{
id: '2',
name: 'Albert Banana - content is very long and will not fit the listbox',
},
{
id: '3',
name: 'Bernard California - content is very long and will not fit the listbox',
},
{
id: '4',
name: 'Cecelia Davenport - content is very long and will not fit the listbox',
},
{
id: '5',
name: 'Doris Evanescence - content is very long and will not fit the listbox',
},
];

export default function App() {
const [value, setSelected] = useState<{ id: string; name: string }>();
const selectId = useId();

return (
<div className="w-96 mx-auto">
<label htmlFor={selectId}>Select a person</label>
<Select
value={value}
onChange={newValue => setSelected(newValue)}
buttonId={selectId}
buttonContent={value ? value.name : <>Select one…</>}
listboxClasses="w-36"
listboxOverflow="wrap"
>
{items.map(item => (
<Select.Option value={item} key={item.id}>
{item.name}
</Select.Option>
))}
</Select>
</div>
);
}

0 comments on commit b9758df

Please sign in to comment.