Skip to content

Dropping skips disabled keys#3192

Merged
snowystinger merged 14 commits intomainfrom
dropping-skips-disabled-keys
Jun 9, 2022
Merged

Dropping skips disabled keys#3192
snowystinger merged 14 commits intomainfrom
dropping-skips-disabled-keys

Conversation

@snowystinger
Copy link
Copy Markdown
Member

@snowystinger snowystinger commented Jun 4, 2022

Closes

Two issues, one that we skipped two keys past a disabled item
second, that we didn't announce "Insert after last item"

Noticed while testing #3135

https://reactspectrum.blob.core.windows.net/reactspectrum/42d6771263b8dc5709e55c73b2b56538702fd957/storybook/index.html?path=/story/listview-drag-and-drop--drag-within-list-reorder

Use keyboard to enter drag mode on Item One. Press down arrow once, it'll jump to between Item Three and Item Four. I would expect it to go between Item Two and Item Three.

We're making use of the ListLayout keyboard delegate to move, we should either add an option to ignore the fact that Item Two is disabled, or we should use some other method.

✅ 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:

🧢 Your Project:

@adobe-bot
Copy link
Copy Markdown

# Conflicts:
#	packages/@react-spectrum/list/test/ListView.test.js
@adobe-bot
Copy link
Copy Markdown

@adobe-bot
Copy link
Copy Markdown

reidbarber
reidbarber previously approved these changes Jun 6, 2022
Copy link
Copy Markdown
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

LGTM, issue is no longer present and the change to KeyboardDelegate seems reasonable

# Conflicts:
#	packages/@react-types/shared/src/collections.d.ts
@adobe-bot
Copy link
Copy Markdown

# Conflicts:
#	packages/@react-spectrum/list/stories/ListView.stories.tsx
#	packages/@react-spectrum/list/test/ListView.test.js
});

// disabledKeys 1 means we actually start on item 2 and drag that, so everything is offset by 1 and it wraps one early
it.each`
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.

new test

@adobe-bot
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

I can see these changes being legitimate + useful outside of useDroppableCollection but lemme know what you think about using collection instead. I haven't tried it myself so there maybe some issues with that approach

Comment on lines +207 to +210
let {keyboardDelegate} = localState.props;
let nextKey = target.type === 'item'
? keyboardDelegate.getKeyBelow(target.key)
: keyboardDelegate.getFirstKey();
? keyboardDelegate.getKeyBelow(target.key, {allowsDisabled: true})
: keyboardDelegate.getFirstKey(null, null, {allowsDisabled: true});
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.

Feels a bit gross needing all the unused options haha. Did you try using the state.collection instead? It should also have similar getFirstKey, getKeyBelow, etc and doesn't skip disabled keys by default.

I'm not sure if we need the other keyboard delegate getters like getPageUp/etc, but it seems like useDroppableCollection only uses above/below/first/last key getters.

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.

I had opted to use the keyboardDelegate first, because that's how we actually navigate, even though yeah, those empty null args feel gross
If I did it with state.collection, then I think i'd just be re-implementing keyboardDelegate
this is more obvious when you think about our grid layouts such as waterfall

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.

Ahhh, I forgot about CardView and how it will support drag and drop. Yeah, the collection route is a no go for that

LFDanLu
LFDanLu previously approved these changes Jun 7, 2022
@adobe-bot
Copy link
Copy Markdown

@adobe-bot
Copy link
Copy Markdown

@adobe-bot
Copy link
Copy Markdown

Comment on lines +90 to +93
export interface KeyboardDelegateOptions {
allowsDisabled?: 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.

can get rid of this now

Comment on lines +128 to +134
let layout = useListLayout(
state,
props.density || 'regular',
// !!0 is false, so we can cast size or undefined and they'll be falsy
state.selectionManager.disabledBehavior === 'selection' || !!dragState?.draggingKeys.size,
overflowMode);

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.

Weird, I get double drop indicators when I start dragging via keyboard in the reorder story:
image
I think it is something with the ListLayout and it getting a new instance due to the drag state change, I noticed the Item 2 row is 47px vs 40px for the other rows

@adobe-bot
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

LGTM

@adobe-bot
Copy link
Copy Markdown

@snowystinger snowystinger merged commit bcbe629 into main Jun 9, 2022
@snowystinger snowystinger deleted the dropping-skips-disabled-keys branch June 9, 2022 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants