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
feat(SimpleList): add simple list #3645
Conversation
PF3 preview: https://patternfly-react-pr-3645-pf3.surge.sh |
cc @jessiehuff
I'm curious what @tlabaj thinks about this. I'm not sure that we have a consistent way of doing this, and it often comes up in the PR when we give an element a class that doesn't have a corresponding style. The main reason we do it is that it helps build the BEM structure (creates a namespace for elements), and allows us to style those elements at some later point without requiring users update their markup to add a new class. That mostly applies to core users, since we can always add a missing class to a react component after the fact. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. @lboehling acn you also take a look?
@mcoker Added your bullets (minus the core one). I went with adding the @jessiehuff Let me know if I'm missing any other aria labels or tags that should be explicitly defined. I think in most cases using the |
Codecov Report
@@ Coverage Diff @@
## master #3645 +/- ##
==========================================
+ Coverage 71.22% 71.29% +0.07%
==========================================
Files 779 782 +3
Lines 10491 10528 +37
Branches 2263 2277 +14
==========================================
+ Hits 7472 7506 +34
- Misses 2592 2594 +2
- Partials 427 428 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!!
/** Additional classes added to the SimpleList <ul> */ | ||
className?: string; | ||
/** Callback when an item is selected */ | ||
onSelect?: (ref: React.RefObject<HTMLButtonElement> | React.RefObject<HTMLAnchorElement>) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of providing the button associated with clicking on each menu option, I'd prefer to provide my own ID. I can get the label from the button, but it's difficult to work with considering the label may be localized.
@dlabaj I believe we may be using SelectOption
to help with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kmcfaul some of the list items seem to be showing an underline on_hover. See below. Why is that?
@mcarrano that's a bug from core. Just put up a PR to fix patternfly/patternfly#2679**** |
packages/patternfly-4/react-core/src/experimental/components/SimpleList/SimpleList.test.tsx
Outdated
Show resolved
Hide resolved
@kmcfaul the underline is fixed patternfly/patternfly#2679 (v2.59.1) |
@dlabrecq However, I could instead add another property to SimpleListItem that would be used to pass back data, instead of props. It would be clearer what gets passed back using this approach but would require extra user input to define the structure. Any thoughts about which approach would be better? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding SimpleListItemProps
packages/patternfly-4/react-core/src/components/SimpleList/SimpleList.tsx
Outdated
Show resolved
Hide resolved
import { css } from '@patternfly/react-styles'; | ||
import styles from '@patternfly/react-styles/css/components/SimpleList/simple-list'; | ||
|
||
export interface SimpleListGroupProps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should extend HTMLProps for section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could only find React.HTMLProps<HTMLTableSectionElement>
, would this be correct? It seems to work with the console logging warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, how about passing <any>
in this case since we just want the default HTML attributes
packages/patternfly-4/react-core/src/components/SimpleList/SimpleListItem.tsx
Outdated
Show resolved
Hide resolved
packages/patternfly-4/react-core/src/components/SimpleList/SimpleList.tsx
Outdated
Show resolved
Hide resolved
packages/patternfly-4/react-core/src/components/SimpleList/SimpleListGroup.tsx
Outdated
Show resolved
Hide resolved
|
||
const componentProps = isButton | ||
? { | ||
type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just making sure this is intended, but type can be submit
or reset
as well if that's what's passed in as prop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want to make sure the default type is "button", this line lets the user change that if they wish. otherwise adding a type
property manually would be caught by the component and not actually set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure either way if we want to allow this
return ( | ||
<li className={css(listItemClassName)}> | ||
<Component | ||
className={css(styles.simpleListItemLink, isCurrentItem && styles.modifiers.current, className)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
className
should be on the root element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved these (className, props) to root element and added properties to customize the inner component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From an accessibility standpoint, it looks pretty good. Similar to what Coker was saying earlier, it would be beneficial to add an aria-labelledby
. However, based on current recommendations, it looks like it should be added to the <ul>
s though, for example here:
This aids the screen reader by being more descriptive about what that list is describing. In VO it will read "list, Group 1, 4 items" instead of "list 4 items" and not telling you which group you're under.
In terms of this pattern in other components like dropdown, app launcher, options menu, etc, I think more research and discussion would be beneficial. It can be a fine line between being descriptive and overusing aria which makes those decisions more challenging.
Great job, Katie! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a followup to @jessiehuff's and @mcoker's comments and based on my VO testing, there are a couple of things you can improve here and that we need to improve upstream.
- Add
aria-labe="Grouped list example"l
to parent list - Add
role="list"
to parent list.pf-c-simple-list
- Add
aria-hidden="true"
to titles
Adding these attributes will announce that the parent .pf-c-simple-list
is a list
, how many sub-lists it contains and will remove title
s from tabindex as they are announced when list is focused.
<div class="pf-c-simple-list" role="list" aria-label="Grouped list example">
<section class="pf-c-simple-list__section">
<h2 id="group-title-1" class="pf-c-simple-list__title" aria-hidden="true">Systems that are neat</h2>
<ul class="" aria-labelledby="group-title-1">
<li class="pf-c-simple-list__item">
<button class="pf-c-simple-list__item-link pf-m-current" type="button">List item 1</button>
</li>
<li class="pf-c-simple-list__item">
<button class="pf-c-simple-list__item-link" type="button">List item 2</button>
</li>
<li class="pf-c-simple-list__item">
<button class="pf-c-simple-list__item-link" type="button">List item 3</button>
</li>
<li class="pf-c-simple-list__item">
<button class="pf-c-simple-list__item-link" type="button">List item 4</button>
</li>
</ul>
</section>
<section class="pf-c-simple-list__section">
<h2 id="group-title-1 " class="pf-c-simple-list__title" aria-hidden="true">Group 2</h2>
<ul class="" aria-labelledby="group-2">
<li class="pf-c-simple-list__item">
<button class="pf-c-simple-list__item-link" type="button">List item 1</button>
</li>
<li class="pf-c-simple-list__item">
<a class="pf-c-simple-list__item-link" href="#">List item 2</a>
</li>
<li class="pf-c-simple-list__item">
<a class="pf-c-simple-list__item-link" href="#">List item 3</a>
</li>
<li class="pf-c-simple-list__item">
<button class="pf-c-simple-list__item-link" type="button">List item 4</button>
</li>
</ul>
</section>
</div>
I would also really like to see the component selectors manually added to the |
6ee92df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
Really great work @kmcfaul ! Only one more thing for me: If |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 LGTM! Nice work!
Your changes have been released in:
Thanks for your contribution! 🎉 |
What: Closes #3610
@mcoker It appears that
pf-c-simple-list__list
andpf-c-simple-list__list-item
do not exist/are not in use despite appearing on the HTML structure in core. Let me know if I should add them manually, but currently I have left them off.