List group
A bordered list of rows, static or actionable.
View as MarkdownExample
- Preview
- Code
Installation
npx fizzy-ui add list-group Copies list-group.ts into src/app/ui/ and installs what it needs. Run init once first.
Accessibility
No axe-core violations axe-core 4.14.0 checks this example, closed and with its panels open, on every build; the site is not published otherwise.
- Use a <ul> for static rows; links and buttons for rows you can act on (each its own Tab stop).
- Mark the current row with aria-current; it is styled from that attribute.
- Not a listbox: for picking options with the arrow keys, use listbox.
Source
The exact file add copies. It is yours to edit.
list-group.ts
import { Directive } from '@angular/core';
/**
* A bordered list of rows: `<ul fzListGroup>` + `<li fzListGroupItem>`, or a `<div fzListGroup>` of
* `<a fzListGroupItem>` / `<button fzListGroupItem>` for rows you can act on (put links in a `nav`).
* Mark the current row with `aria-current` (`page`, `true`…), a disabled button with `disabled`.
*/
@Directive({
selector: '[fzListGroup]',
host: { class: 'flex w-full flex-col divide-y overflow-hidden rounded-md border bg-background text-sm' },
})
export class FzListGroup {}
@Directive({
selector: '[fzListGroupItem]',
host: {
class:
'flex w-full items-center gap-3 px-4 py-3 text-start outline-none ' +
// only links and buttons react to the pointer
'[a&]:cursor-pointer [button&]:cursor-pointer [a&]:hover:bg-accent [button&]:hover:bg-accent [a&]:transition-colors [button&]:transition-colors ' +
'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset ' +
'aria-[current]:bg-accent aria-[current]:font-medium aria-[current]:text-accent-foreground ' +
'disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50',
},
})
export class FzListGroupItem {}
export const FZ_LIST_GROUP = [FzListGroup, FzListGroupItem] as const;