List Group

The List Group component offers a flexible, customizable way to display items like links or text in a list format. It supports various styles and types, making it ideal for structured content.

Example

To use the List Group component, import it from the theui-svelte library. Below is a simple example demonstrating how to use the List Group:

  • First Item
  • Second Item
  • Third Item
Svelte
<script>
  import { ListGroup, ListItem } from "theui-svelte";
</script>

<ListGroup>
  <ListItem>First Item</ListItem>
  <ListItem>Second Item</ListItem>
  <ListItem>Third Item</ListItem>
</ListGroup>

List Style Variant

The variant prop in the List Group component allows you to control the overall style of the list. It provides two options:

  • bordered: This style adds borders around each list item, giving a defined and structured look to the list. It is useful when you want to visually separate items clearly.
  • flat: This style removes borders, resulting in a clean, minimalist design. It's ideal for cases where a simple and unobtrusive list presentation is preferred.

By default, the variant is set to "bordered". You can easily switch between these styles to match the design needs of your application.

  • First Item
  • Second Item
  • Third Item
Svelte
<ListGroup variant="flat">
  <ListItem>First Item</ListItem>
  <ListItem>Second Item</ListItem>
  <ListItem>Third Item</ListItem>
</ListGroup>

List Element Type

The type prop in the List Group component determines the HTML element used to render the list. This allows you to customize the structure of the list based on your needs. The available options are:

  • ul (default): Renders the list as an unordered list (<ul>), which is ideal for general list items or navigation. Each ListItem will be a <li> in that case.
  • div: Setting type="div" renders each ListItem as a <div> by default. If the ListItem has an href, it becomes an <a>. Without href, it stays as a <div>. This allows a mix of static and clickable content.
Svelte
<ListGroup type="div">
  <ListItem>Non-clickable item</ListItem>
  <ListItem href="/link">Clickable link item</ListItem>
</ListGroup>

Accessibility

The List Group component ensures accessibility by using semantic HTML and ARIA roles:

  1. The parent container <ul> includes role="list"
  2. Each <li> element has role="listitem" to provide proper structure for assistive technologies.

To maintain accessibility:

  1. Ensure sufficient color contrast for readability.
  2. Interactive list items should be focusable and navigable using a keyboard.
  3. Add labels like `aria-label` if additional context is required for interactive elements.

Configuration

List Group

List Item