Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/react-core/src/components/SimpleList/SimpleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface SimpleListProps extends Omit<React.HTMLProps<HTMLDivElement>, '
) => void;
/** Indicates whether component is controlled by its internal state */
isControlled?: boolean;
/** aria-label for the <ul> element that wraps the SimpleList items. */
'aria-label'?: string;
}

export interface SimpleListState {
Expand Down Expand Up @@ -57,7 +59,7 @@ export class SimpleList extends React.Component<SimpleListProps, SimpleListState

render() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { children, className, onSelect, isControlled, ...props } = this.props;
const { children, className, onSelect, isControlled, 'aria-label': ariaLabel, ...props } = this.props;

let isGrouped = false;
if (children) {
Expand All @@ -74,7 +76,7 @@ export class SimpleList extends React.Component<SimpleListProps, SimpleListState
>
<div className={css(styles.simpleList, className)} {...props}>
{isGrouped && children}
{!isGrouped && <ul>{children}</ul>}
{!isGrouped && <ul aria-label={ariaLabel}>{children}</ul>}
</div>
</SimpleListContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe('SimpleList', () => {
expect(asFragment()).toMatchSnapshot();
});

test('renders aria-labelled content', () => {
const { asFragment } = render(<SimpleList aria-label="This is a simple list">{items}</SimpleList>);
expect(asFragment()).toMatchSnapshot();
});

test('renders grouped content', () => {
const { asFragment } = render(
<SimpleList>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SimpleList renders aria-labelled content 1`] = `
<DocumentFragment>
<div
class="pf-c-simple-list"
>
<ul
aria-label="This is a simple list"
>
<li
class=""
>
<button
class="pf-c-simple-list__item-link"
type="button"
>
Item 1
</button>
</li>
<li
class=""
>
<button
class="pf-c-simple-list__item-link"
type="button"
>
Item 2
</button>
</li>
<li
class=""
>
<button
class="pf-c-simple-list__item-link"
type="button"
>
Item 3
</button>
</li>
</ul>
</div>
</DocumentFragment>
`;

exports[`SimpleList renders content 1`] = `
<DocumentFragment>
<div
Expand Down