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

feat: pf-pagination (bottom variant) #2455

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

eyevana
Copy link
Contributor

@eyevana eyevana commented Mar 28, 2023

What I did

Testing Instructions

Notes to Reviewers

@changeset-bot
Copy link

changeset-bot bot commented Mar 28, 2023

⚠️ No Changeset found

Latest commit: ad26eb2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added work in progress POC / Not ready for review demo Updating demo pages doc functionality Functionality, typically pertaining to the JavaScript. styles An issue or PR pertaining only to CSS/Sass tests Related to testing labels Mar 28, 2023
@github-actions github-actions bot added this to In progress in Workflow Mar 28, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 28, 2023

Deploy Preview for patternfly-elements ready!

Name Link
🔨 Latest commit f411ab5
😎 Deploy Preview https://deploy-preview-2455--patternfly-elements.netlify.app/

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the AT passed Automated testing has passed label Mar 28, 2023
@bennypowers
Copy link
Member

PTAL at the prior art in rh-pagination, and see how much you can move to shared code like a controller or some such

@eyevana
Copy link
Contributor Author

eyevana commented Mar 29, 2023

@bennypowers yep, I'll compare the two implementations now.

Copy link
Collaborator

@nikkimk nikkimk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a good draft. I have a few suggestions marked.

(And it gave me an opportunity to really, really have to think about one of those tricker accessibility questions, so thanks much for helping me get better at my work!)

class="${classMap({ expanded: this._expanded })}">
<pf-button id="menu-toggle"
aria-expanded=${this._expanded}
aria-haspopup="listbox"
Copy link
Collaborator

@nikkimk nikkimk Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aria-attributes you have done correctly correct--nice!

(Note: There's this subtle distinction between a combobox with listbox and a menu, that even I had to really pause and think on. And I almost wanted to change your aria-haspopup to menu above, but then I realized that you are correct and this is really doing what a <select> would do and retains your selection, not what a menu would do. This choice will be important in my comments later because it will determine other choices, and my comments, in the code.)

You will also need to add the following:

  • aria-controls="menu-list"
  • role="combobox"
  • aria-label="Show items" (or whatever label makes sense)
  • aria-activedescendant when listbox is open, this should be set to id of listbox option receiving focus

See Select Only Combobox Example

<span><b>${this.#firstOfPage()}-${this.#lastOfPage()}</b> ${TITLES.ofWord} <b>${this.count}</b></span>
</pf-button>
<ul id="menu-list"
part="menu-list">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add role="listbox" since we're going with listbox over menu.

icon=${ifDefined(this.#selected(option) ? 'check' : undefined)}
icon-position=${ifDefined(this.#selected(option) ? 'right' : undefined)}
part="menu-item"
role="menuitem">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to role=option since we're going with listbox

part="menu-toggle"
plain
type="button"
@click=${this.#toggleExpanded}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also need to add @keydown to handle the following:

  • Down Arrow : Opens the listbox if it is not already displayed without moving focus or changing selection. DOM focus remains on the combobox.
  • Alt + Down Arrow: Opens the listbox without moving focus or changing selection.
  • Up Arrow: First opens the listbox if it is not already displayed and then moves visual focus to the first option. DOM focus remains on the combobox.
  • Home: Opens the listbox and moves visual focus to the first option.
  • End: Opens the listbox and moves visual focus to the last option.
  • Printable characters: First opens the listbox if it is not already displayed and then moves visual focus to the first option that matches the typed character. If multiple keys are typed in quick succession, visual focus moves to the first option that matches the full string. If the same character is typed in succession, visual focus cycles among the options starting with that character. <--- I feel like in this use case, it's a nice-to-have but doesn't have to be part of an MVP.

See Closed combobox

${PER_PAGE_OPTIONS.map(option => html`<li role="none">
<pf-button variant="tertiary"
block
class="${classMap({ ['menu-item']: true, selected: this.#selected(option) })}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll also want to set an aria-selected based on which item is currently selected

this.#paginate('per-page');
}

@bound private _outsideClick(event: MouseEvent) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to do this might be to capture @focusout on your combo/listbox.

}

#toggleExpanded() {
this._expanded = !this._expanded;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When listbox closes, focus needs to go back to the toggle button.

plain
type="button"
@click=${this.#toggleExpanded}>
<span><b>${this.#firstOfPage()}-${this.#lastOfPage()}</b> ${TITLES.ofWord} <b>${this.count}</b></span>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${this.count} doesn't seem to be working in demo.

return;
case Action.PerPage:
if (value) {
this.perPage = parseInt(value, 10);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a user:

  • If I'm viewing 10 items at a time, and I'm on page 4 (items 31-40), when I switch to 20 per page, I'd expect to be on page 2 (items 21-40) instead of page 4 (items 61-80) so that I wouldn't miss items.
  • If I'm viewing 20 items at a time, and I'm on page 4 (items 61-80), when I switch to 10 per page, I'd expect to be on page 6 (items 61-70) instead of page 4 (items 31-40) so that I wouldn't have to navigate back to the items I was on.

@@ -570,7 +570,7 @@ button:hover {
:host([block]) button {
display: flex;
width: 100%;
justify-content: var(--pf-c-button--JustifyContent, center);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor Author

@eyevana eyevana Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this and opened that separate PR to add the CSS var, but opting for a part on the button instead.

https://github.com/patternfly/patternfly-elements/pull/2470/files

@markcaron markcaron removed the doc label Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AT passed Automated testing has passed demo Updating demo pages functionality Functionality, typically pertaining to the JavaScript. styles An issue or PR pertaining only to CSS/Sass tests Related to testing work in progress POC / Not ready for review
Projects
Workflow
In progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants