forked from cerner/terra-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[terra-list] Add programmatic support for single/multi-select (cerner…
…#3703) * Added prop for single/multi select a11y support * Updated ariaSelectionStyle logic * Updated terra-list single and multi select guides * Updated jest snapshots * Revert snapshot * Added intl for helper text * Moved translations * Updated tests * Updated react-intl version * Update react-intl version * Update tests and react-intl dependency version * Added tests for ariaSelectionStyle * Added translations Co-authored-by: Parkeenvincha,Art <[email protected]>
- Loading branch information
Showing
20 changed files
with
725 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/terra-core-docs/src/terra-dev-site/test/list/MultiSelectList.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import List, { Item, Utils } from 'terra-list/lib/index'; | ||
import { Placeholder } from '@cerner/terra-docs'; | ||
|
||
const mockData = [ | ||
{ | ||
title: 'Item 0', | ||
key: 'unique-0', | ||
}, | ||
{ | ||
title: 'Item 1', | ||
key: 'unique-1', | ||
}, | ||
{ | ||
title: 'Item 2', | ||
key: 'unique-2', | ||
}, | ||
{ | ||
title: 'Item 3', | ||
key: 'unique-3', | ||
}, | ||
{ | ||
title: 'Item 4', | ||
key: 'unique-4', | ||
}, | ||
]; | ||
|
||
const maxSectionCount = 3; | ||
|
||
class MutliSelectList extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.createListItem = this.createListItem.bind(this); | ||
this.handleItemSelection = this.handleItemSelection.bind(this); | ||
this.state = { selectedKeys: [] }; | ||
} | ||
|
||
handleItemSelection(event, metaData) { | ||
event.preventDefault(); | ||
this.setState(state => ({ selectedKeys: Utils.updatedMultiSelectedKeys(state.selectedKeys, metaData.key) })); | ||
} | ||
|
||
createListItem(itemData) { | ||
return ( | ||
<Item | ||
key={itemData.key} | ||
isSelectable={Utils.shouldBeMultiSelectable(maxSectionCount, this.state.selectedKeys, itemData.key)} | ||
isSelected={this.state.selectedKeys.indexOf(itemData.key) >= 0} | ||
metaData={{ key: itemData.key }} | ||
onSelect={this.handleItemSelection} | ||
> | ||
<Placeholder title={itemData.title} /> | ||
</Item> | ||
); | ||
} | ||
|
||
createListItems(data) { | ||
return data.map(childItem => this.createListItem(childItem)); | ||
} | ||
|
||
render() { | ||
return ( | ||
<List dividerStyle="standard" ariaSelectionStyle="multi-select"> | ||
{this.createListItems(mockData)} | ||
</List> | ||
); | ||
} | ||
} | ||
|
||
export default MutliSelectList; |
70 changes: 70 additions & 0 deletions
70
packages/terra-core-docs/src/terra-dev-site/test/list/SingleSelectList.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import List, { Item } from 'terra-list/lib/index'; | ||
import { Placeholder } from '@cerner/terra-docs'; | ||
|
||
const mockData = [ | ||
{ | ||
title: 'Item 0', | ||
key: 'unique-0', | ||
}, | ||
{ | ||
title: 'Item 1', | ||
key: 'unique-1', | ||
}, | ||
{ | ||
title: 'Item 2', | ||
key: 'unique-2', | ||
}, | ||
{ | ||
title: 'Item 3', | ||
key: 'unique-3', | ||
}, | ||
{ | ||
title: 'Item 4', | ||
key: 'unique-4', | ||
}, | ||
]; | ||
|
||
class SingleSelectList extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.createListItem = this.createListItem.bind(this); | ||
this.handleItemSelection = this.handleItemSelection.bind(this); | ||
this.state = { selectedKey: null }; | ||
} | ||
|
||
handleItemSelection(event, metaData) { | ||
event.preventDefault(); | ||
if (this.state.selectedKey !== metaData.key) { | ||
this.setState({ selectedKey: metaData.key }); | ||
} | ||
} | ||
|
||
createListItem(itemData) { | ||
return ( | ||
<Item | ||
key={itemData.key} | ||
isSelectable | ||
isSelected={this.state.selectedKey === itemData.key} | ||
metaData={{ key: itemData.key }} | ||
onSelect={this.handleItemSelection} | ||
> | ||
<Placeholder title={itemData.title} /> | ||
</Item> | ||
); | ||
} | ||
|
||
createListItems(data) { | ||
return data.map(childItem => this.createListItem(childItem)); | ||
} | ||
|
||
render() { | ||
return ( | ||
<List dividerStyle="standard" ariaSelectionStyle="single-select"> | ||
{this.createListItems(mockData)} | ||
</List> | ||
); | ||
} | ||
} | ||
|
||
export default SingleSelectList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.