Skip to content

ListView hook refactor#3086

Merged
LFDanLu merged 54 commits into
mainfrom
listview_hooks
May 12, 2022
Merged

ListView hook refactor#3086
LFDanLu merged 54 commits into
mainfrom
listview_hooks

Conversation

@LFDanLu
Copy link
Copy Markdown
Member

@LFDanLu LFDanLu commented Apr 29, 2022

Relies on #3000

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Quite the refactor so ListView need to be throughly retested, keyboard behavior especially.

🧢 Your Project:

RSP

LFDanLu added 30 commits March 31, 2022 14:46
Felt that the previous modifications to GridKeyboardDelegate were too specific to ListView so split out the changes. Also fixes pageUp/Down/Home/End when you are focused on the ListView row (we forgot to pass the layout to the delegate previously)
needed to override getItemRect for the ListView keyboard delegate so that it always uses the row key, namely due to the gridcell keys being unavailable in the listlayout. Changed getItem and getItemRect to protected funcs in GridKeyboardDelegate so I could do that
needed to override getKeyLeftOf/getKeyRightOf so they dont use getFirstKey or getLastKey or else focus would jump to the last row instead of wrapping inside the cell
also reverts changes to other files that arent necessary anymore. Adds tests for disabled keys
@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

snowystinger
snowystinger previously approved these changes May 10, 2022
solimant
solimant previously approved these changes May 11, 2022
Copy link
Copy Markdown
Collaborator

@solimant solimant left a comment

Choose a reason for hiding this comment

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

Looks good, just one minor comment 👍🏼

* governing permissions and limitations under the License.
*/

jest.mock('@react-aria/live-announcer');
Copy link
Copy Markdown
Collaborator

@solimant solimant May 11, 2022

Choose a reason for hiding this comment

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

Jest hoists jest.mock calls to the top of the module and before any imports. So, it should be okay to push this line down after the imports block, and Jest will still call it first (unless that's the coding style we're following in our tests).

EDIT: looks like that's the coding style we're following 😅

reidbarber
reidbarber previously approved these changes May 11, 2022
@LFDanLu LFDanLu dismissed stale reviews from reidbarber, solimant, and snowystinger via 0f73c40 May 11, 2022 16:42
@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉


export interface ListViewAria {
/** Props for the grid element. */
gridProps: HTMLAttributes<HTMLElement>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think gridProps. We tend to match the role, and if we changed this one it wouldn't match with rowProps/cellProps from useListItem.

Comment on lines +120 to +122
let selection = state.selectionManager.rawSelection;
let lastSelection = useRef(selection);
useUpdateEffect(() => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should remain in the grid package (I think the live announcer wasn't necessary for other roles with selection, e.g. listbox?), and be exported as a separate hook.

let id = useId();
listMap.set(state, {id, onAction});

// This is useHighlightSelectionDescription copy pasted, it isn't exposed by react-aria/grid.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I would just expose it from the grid package for now. The solution might be different for other roles. The reason the description is on the whole grid and not each individual row is due to limitations of VoiceOver, for listbox or other roles it works better.

/** Whether selection should occur on press up instead of press down. */
shouldSelectOnPressUp?: boolean,
/** Whether the list item is disabled. */
isDisabled?: boolean
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this shouldn't be necessary since we have disabledKeys. I believe this option was legacy in grid.

focus
});

let onKeyDown = (e: ReactKeyboardEvent) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Worth it to extract this keyboard navigation stuff into a separate hook?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah it would be useful for other single column grid like components, I can pull it out into its own hook when we need it. Not sure there is one that exists right now though (TagGroup handles left/right differently), but I maybe forgetting one

@devongovett
Copy link
Copy Markdown
Member

I think due to the duplicated translations, we should expose more things from the grid package to reuse. I am now thinking of the grid package as something we wouldn't document directly, more of a lower level building block for components like table and list. So I think it's ok to expose more pieces from there that we can reuse in components that use the grid role.

@LFDanLu
Copy link
Copy Markdown
Member Author

LFDanLu commented May 11, 2022

@devongovett sounds good, mind if I handle those in a followup? I think it will make the code diff much cleaner since there won't be a bunch of ListView specific refactor code changes then.

@devongovett
Copy link
Copy Markdown
Member

Yeah sure

devongovett
devongovett previously approved these changes May 11, 2022
@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

Comment on lines +176 to 178
// TODO: Figure out the typescript for this
// @ts-ignore
if (y >= r.y + 10 && y <= r.maxY - 10 && collection.getItem(closest.key).value.type === 'folder') {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ts-ignoring this for now because value.type doesn't fit the generic type that value gets here. Will update the logic when we decide whether or not to make the type more restrictive for ListView (aka user has to provide type to their items) or if we change this logic overall

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Turns out value.type is not alway going to be defined, but only specifically for static ListViews which I don't think makes sense w/ drag and drop in general. Perhaps just to be safer we should change this to be collection.getItem(closest.key).hasChildNodes but we should discuss what the true restrictions for "on" drops should be. Will handle in followup

found when testing screen reader announcements
@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

Copy link
Copy Markdown
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

everything appears to be in working order, re-approving

@LFDanLu LFDanLu merged commit 4dc28ea into main May 12, 2022
@LFDanLu LFDanLu deleted the listview_hooks branch May 12, 2022 20:18
@LFDanLu LFDanLu mentioned this pull request May 13, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants