An ActionBar is a companion component intended to facilitate bulk actions on selected items within a collection component. It consists of an ActionGroup, a clear button, and a count of selected items. It accepts a list of Item
elements as children, each with a key prop. Alternatively, a function that returns Item elements is also supported as seen below. See the collection components
docs for more details about this API. These Item elements are used to populate the ActionBar's ActionGroup and thus follows the same content guidelines when it comes to customization and labeling.
functionExample(){letbarItems=[{key: 'edit',label: 'Edit'},{key: 'copy',label: 'Copy'},{key: 'delete',label: 'Delete'}];letlistItems=[{key: 0,name: 'Adobe Photoshop'},{key: 1,name: 'Adobe Illustrator'},{key: 2,name: 'Adobe XD'}];let[selectedKeys,setSelectedKeys]=React.useState(newSet([0]));return(<ActionBarContainerheight={300}maxWidth="size-6000"><ListViewitems={listItems}aria-label="ListView with action bar, dynamic collection"selectionMode="multiple"selectedKeys={selectedKeys}onSelectionChange={setSelectedKeys}>{(item)=>(<Item>{item.name}</Item>)}</ListView><ActionBaritems={barItems}selectedItemCount={selectedKeys==='all'
? items.length
: selectedKeys.size}onAction={(key)=>alert(`Performing ${key} action on ${selectedKeys.size} rows.`)}onClearSelection={()=>setSelectedKeys(newSet([]))}isEmphasized>{(item)=>(<Itemkey={item.key}>{item.label}</Item>)}</ActionBar></ActionBarContainer>);}<Example/>
functionExample(){letbarItems=[{key: 'edit',label: 'Edit'},{key: 'copy',label: 'Copy'},{key: 'delete',label: 'Delete'}];letlistItems=[{key: 0,name: 'Adobe Photoshop'},{key: 1,name: 'Adobe Illustrator'},{key: 2,name: 'Adobe XD'}];let[selectedKeys,setSelectedKeys]=React.useState(newSet([0]));return(<ActionBarContainerheight={300}maxWidth="size-6000"><ListViewitems={listItems}aria-label="ListView with action bar, dynamic collection"selectionMode="multiple"selectedKeys={selectedKeys}onSelectionChange={setSelectedKeys}>{(item)=>(<Item>{item.name}</Item>)}</ListView><ActionBaritems={barItems}selectedItemCount={selectedKeys==='all'
? items.length
: selectedKeys.size}onAction={(key)=>alert(`Performing ${key} action on ${selectedKeys.size} rows.`)}onClearSelection={()=>setSelectedKeys(newSet([]))}isEmphasized>{(item)=>(<Itemkey={item.key}>{item.label}</Item>)}</ActionBar></ActionBarContainer>);}<Example/>
functionExample(){letbarItems=[{key: 'edit',label: 'Edit'},{key: 'copy',label: 'Copy'},{key: 'delete',label: 'Delete'}];letlistItems=[{key: 0,name:
'Adobe Photoshop'},{key: 1,name:
'Adobe Illustrator'},{key: 2,name: 'Adobe XD'}];let[selectedKeys,setSelectedKeys]=React.useState(newSet([0]));return(<ActionBarContainerheight={300}maxWidth="size-6000"><ListViewitems={listItems}aria-label="ListView with action bar, dynamic collection"selectionMode="multiple"selectedKeys={selectedKeys}onSelectionChange={setSelectedKeys}>{(item)=>(<Item>{item.name}</Item>)}</ListView><ActionBaritems={barItems}selectedItemCount={selectedKeys==='all'
? items.length
: selectedKeys.size}onAction={(key)=>alert(`Performing ${key} action on ${selectedKeys.size} rows.`)}onClearSelection={()=>setSelectedKeys(newSet([]))}isEmphasized>{(item)=>(<Itemkey={item.key}>{item.label}</Item>)}</ActionBar></ActionBarContainer>);}<Example/>
To internationalize an ActionBar, the content provided to all child items should be localized. A localized string for the selection count and clear button aria-label will be provided
automatically. For languages that are read right-to-left (e.g. Hebrew and Arabic), the layout of the ActionBar is automatically flipped.
Use the onClearSelection prop as a callback to handle when the clear button in the ActionBar is pressed. Additionally, the onAction prop can be used as a callback for when the user
presses any of the buttons in the ActionBar's ActionGroup. The key from the pressed button will be passed into the callback.
The following example clears row selection within the TableView when the clear button is pressed and alerts the user as to what
action is being taken on the selected rows when the ActionButtons are pressed.
functionActionBarActions(props){// Same bar items, table columns, and table rows as example above...return(<ActionBarContainerheight="size-5000"><TableViewaria-label="Table with action bar and controlled selection"selectionMode="multiple"selectedKeys={selectedKeys}onSelectionChange={setSelectedKeys}height="size-3000"><TableHeadercolumns={columns}>{(column)=>(<Columnkey={column.uid}align={column.uid==='level' ? 'end' : 'start'}>{column.name}</Column>)}</TableHeader><TableBodyitems={rows}>{(item)=>(<Row>{(columnKey)=><Cell>{item[columnKey]}</Cell>}</Row>)}</TableBody></TableView><ActionBaritems={barItems}isEmphasizedselectedItemCount={selectedKeys==='all'
? selectedKeys
: selectedKeys.size}onClearSelection={()=>{setSelectedKeys(newSet());}}onAction={(key)=>alert(`Performing ${key} action on ${selectedKeys.size} rows.`)}>{(item)=>(<Itemkey={item.key}>{item.label}</Item>)}</ActionBar></ActionBarContainer>);}
functionActionBarActions(props){// Same bar items, table columns, and table rows as example above...return(<ActionBarContainerheight="size-5000"><TableViewaria-label="Table with action bar and controlled selection"selectionMode="multiple"selectedKeys={selectedKeys}onSelectionChange={setSelectedKeys}height="size-3000"><TableHeadercolumns={columns}>{(column)=>(<Columnkey={column.uid}align={column.uid==='level'
? 'end'
: 'start'}>{column.name}</Column>)}</TableHeader><TableBodyitems={rows}>{(item)=>(<Row>{(columnKey)=>(<Cell>{item[columnKey]}</Cell>)}</Row>)}</TableBody></TableView><ActionBaritems={barItems}isEmphasizedselectedItemCount={selectedKeys==='all'
? selectedKeys : selectedKeys.size}onClearSelection={()=>{setSelectedKeys(newSet());}}onAction={(key)=>alert(`Performing ${key} action on ${selectedKeys.size} rows.`)}>{(item)=>(<Itemkey={item.key}>{item.label}</Item>)}</ActionBar></ActionBarContainer>);}
functionActionBarActions(props){// Same bar items, table columns, and table rows as example above...return(<ActionBarContainerheight="size-5000"><TableViewaria-label="Table with action bar and controlled selection"selectionMode="multiple"selectedKeys={selectedKeys}onSelectionChange={setSelectedKeys}height="size-3000"><TableHeadercolumns={columns}>{(column)=>(<Columnkey={column.uid}align={column.uid==='level'
? 'end'
: 'start'}>{column.name}</Column>)}</TableHeader><TableBodyitems={rows}>{(item)=>(<Row>{(columnKey)=>(<Cell>{item[columnKey]}</Cell>)}</Row>)}</TableBody></TableView><ActionBaritems={barItems}isEmphasizedselectedItemCount={selectedKeys==='all'
? selectedKeys
: selectedKeys.size}onClearSelection={()=>{setSelectedKeys(newSet());}}onAction={(key)=>alert(`Performing ${key} action on ${selectedKeys.size} rows.`)}>{(item)=>(<Itemkey={item.key}>{item.label}</Item>)}</ActionBar></ActionBarContainer>);}
isEmphasized should be applied to the ActionBar when it should call attention, such as when floating in a TableView. It should be omitted if the ActionBar should blend in
with the rest of the UI, directing a user’s focus to elsewhere in a view.