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

Create ActionListItem Component #1718

Open
Tracked by #1705
scurker opened this issue Oct 11, 2024 · 0 comments
Open
Tracked by #1705

Create ActionListItem Component #1718

scurker opened this issue Oct 11, 2024 · 0 comments
Labels
info needed rfc An issue proposing a new significant change
Milestone

Comments

@scurker
Copy link
Member

scurker commented Oct 11, 2024

ActionListItem is a primitive collection of components that renders elements as action item(s) within an ActionList or ActionListGroup. It is intended to be a replacement for the existing OptionsMenuItem component with some additional options.

Related:

This is an implementation of an aria menu pattern implementing the various roles and states necessary for menu items with selection(s).

Props

type ActionListItemBaseProps = {

  /** 
   * A unique key to identify the action when triggered, when not provided 
   * will use the child text content as the key. 
   */
  key?: string

  /** Provides an additional description for the list item. */
  description?: ContentNode

  /** Indicates if the current action list item is selected. */
  selected?: ContentNode

  /** When an action list item is disabled, it cannot be selected or activated. */
  disabled?: boolean

  /** A callback function that is called when an action list item is selected. */
  onAction: (event: React.MouseEvent<HTMLLIElement> | React.KeyboardEvent<HTMLLIElement>) => void

}

type ActionListItemProps = ActionListItemBaseProps & React.HTMLAttributes<HTMLLIElement>

type ActionListLinkItemProps = {

  /** URL to link to for this action list item */
  href: string

} & Omit<ActionListItemBaseProps, 'selected'> & React.AnchorHTMLAttributes<HTMLAnchorElement>

type ActionListSeparatorProps = React.HTMLAttributes<HTMLLIElement>

Implementations

The below components are intended to be direct children of an ActionList or ActionListGroup component.

ActionListItem

The role of the action list item is dependent on how it it rendered within an ActionList or ActionListGroup component:

  • If the selection type of the closest ActionList or ActionListGroup is not set, use role="menuitem"
  • If the selection type of the closest ActionList or ActionListGroup is set to single, use role="menuitemradio"
  • If the selection type of the closest ActionList of ActionListGroup is set to multiple, use role="menuitemcheckbox"

Each action list item should always have an id set for aria associations, either via props or using react-id-generator:

const [id] = propId ? [propId] : useId(1, 'action-list-item')

When disabled is set to true, aria-disabled should be set to true and any click or keypress events for the disabled item should be prevented.

When selected is set to true, aria-checked should be set if the role of the item is menuitemradio or menuitemcheckbox.

The description property should be displayed immediately below any children content of the ActionListItem. This can utilize a flex layout.

ActionListLinkItem

This component is an extension of the ActionListItem component but with an anchor child. The onAction event should be captured as an event on the child and not the li element.

ActionListSeparator

This is a display component with a role of separator. This component should only accept HTMLLiElement properties and a ref with no children.

@scurker scurker added the rfc An issue proposing a new significant change label Oct 11, 2024
@scurker scurker added this to the Q4 2024 milestone Oct 11, 2024
@scurker scurker changed the title Create ActionMenuItem Component Create ActionItem Component Oct 21, 2024
@scurker scurker changed the title Create ActionItem Component Create ActionListItem Component Oct 21, 2024
@scurker scurker added the rocket label Oct 25, 2024
@scurker scurker modified the milestones: Q4 2024, Future Nov 21, 2024
@scurker scurker removed the rocket label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info needed rfc An issue proposing a new significant change
Projects
None yet
Development

No branches or pull requests

1 participant