Skip to content
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

Document the Select component listboxOverflow #1754

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 49 additions & 15 deletions src/pattern-library/components/patterns/prototype/SelectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,33 @@ export default function SelectPage() {
</div>
</Library.Demo>
</Library.Example>
<Library.Example title="listboxAsPopover">
<Library.Info>
<Library.InfoItem label="description">
Determines if the listbox should be rendered using the{' '}
<Link
target="_blank"
href="https://developer.mozilla.org/en-US/docs/Web/API/Popover_API"
>
popover API
</Link>
. It{"'"}s mainly used as a test seam, but can help explicitly
disabling this behavior if needed.
</Library.InfoItem>
<Library.InfoItem label="type">
<code>boolean</code>
</Library.InfoItem>
<Library.InfoItem label="default">
<code>true</code> if the browser supports <code>[popover]</code>
. Otherwise it is <code>false</code>
</Library.InfoItem>
</Library.Info>
<Library.Demo
title="Non-popover listbox"
exampleFile="select-non-popover-listbox"
withSource
/>
</Library.Example>
<Library.Example title="listboxClasses">
<Library.Info>
<Library.InfoItem label="description">
Expand All @@ -405,30 +432,37 @@ export default function SelectPage() {
</div>
</Library.Demo>
</Library.Example>
<Library.Example title="listboxAsPopover">
<Library.Example title="listboxOverflow">
acelaya marked this conversation as resolved.
Show resolved Hide resolved
<Library.Info>
<Library.InfoItem label="description">
Determines if the listbox should be rendered using the{' '}
<Link
target="_blank"
href="https://developer.mozilla.org/en-US/docs/Web/API/Popover_API"
>
popover API
</Link>
. It{"'"}s mainly used as a test seam, but can help explicitly
disabling this behavior if needed.
Determines the behavior of the listbox options when their
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Determines the behavior of the listbox options when their
Determines the behavior of the listbox options when their

"options" or "items"? The component is called Select.Option but code examples tend to use the term "items" for the data arrays from which the options are generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would use "items" when conceptually talking about the entries of the list, and "options" when talking about the markup elements explicitly.

In this case, since we are talking about how they render, I think I would use "options".

But this is not a strong opinion, and I see a lot of grey areas in that reasoning, so I'm ok using a different wording.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would use "items" when conceptually talking about the entries of the list, and "options" when talking about the markup elements explicitly.

That makes sense.

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>boolean</code>
<code>{"'truncate' | 'wrap'"}</code>
</Library.InfoItem>
<Library.InfoItem label="default">
<code>true</code> if the browser supports <code>[popover]</code>
. Otherwise it is <code>false</code>
<code>{"'truncate'"}</code>
</Library.InfoItem>
</Library.Info>
<Library.Demo
title="Non-popover listbox"
exampleFile="select-non-popover-listbox"
title="Truncate listbox options"
exampleFile="select-truncate-listbox"
withSource
/>
<Library.Demo
title="Wrap listbox options"
exampleFile="select-wrap-listbox"
withSource
/>
</Library.Example>
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>
);
}