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

Update dnd examples to focus inserted items on drop #1721

Merged
merged 6 commits into from Apr 15, 2021
Merged

Conversation

devongovett
Copy link
Member

@devongovett devongovett commented Mar 22, 2021

Behavior is:

  • If dropping between two items, the dropped items are selected and the first one is focused.
  • If dropping on an item, that item becomes focused and the focus ring is shown.
  • When inserting between items but no items are added (e.g. they are reordered), the focus ring is shown only if the moved item is not selected.

@adobe-bot
Copy link

Build successful! 🎉

@majornista
Copy link
Collaborator

  1. Should the dropped items be selected? I did this to match macOS finder behavior.

When dropping a single item in between items in the list, I don't think it should become selected unless it was selected before the drag and drop operation.

Since dragging multiple items requires the items to be selected, I think the behavior you have implemented, where items dropped between items in the list remain selected, and the first of the items has focus is appropriate.

When dropping one or more items on an item, like a folder, the drop target should display focus, but I don't think the drop target should become selected if it was not already selected.

  1. Should the focus ring appear on mouse drops? My feeling was that if selection occurred this wasn't necessary, but if we don't select the dropped items then maybe it should to give some kind of feedback?

I think you're right about this, if we don't select the dropped items and there is no focus ring or focused state when you drop the items, it may be difficult for a mouse user to remember which items were dropped.

  1. The current API requires the user do this manually. Is there a way we can make this automatic?

That would be ideal because, depending on the complexity of implementing this behavior manually, users might opt to omit it.

@LFDanLu
Copy link
Member

LFDanLu commented Apr 1, 2021

  1. I think this is fine, matches with Windows behavior as well. As for the single item case that @majornista mentioned, I'm not entirely sure. Might be nice to auto select the dropped item for certain user flows e.g. could then do Shift+Arrow key commands immediately after to select a couple of other items in the droppable collection in preparation for a second drag/copy/cut operation.
  2. It would definitely be nice to have some kind of indicator of where focus was currently located after a mouse drag operation. Windows has a light blue focus ring outline (in contrast to the filled blue box when selection is made) after a drag operation which reappears whenever you re-enter the file window via mouse or keyboard.
  3. No idea, I would need to play around with it to see if there is a way to do this automatically.

@devongovett
Copy link
Member Author

When dropping a single item in between items in the list, I don't think it should become selected unless it was selected before the drag and drop operation.

I don't think we can know this in general, e.g. when dragging from Finder or somewhere outside the page. Feels to me like selecting is useful in most cases, especially when dropping multiple items since we can't focus multiple items at once.

When dropping one or more items on an item, like a folder, the drop target should display focus, but I don't think the drop target should become selected if it was not already selected.

Yeah I agree. Updated to just show the focus ring instead when dropping on an item and no items are inserted.

That would be ideal because, depending on the complexity of implementing this behavior manually, users might opt to omit it.

Yeah agreed. I added support for doing this by default, but there are some limitations. You must insert the items immediately on drop (within 50ms). When asynchronous behavior is involved things get very complicated very quickly. We can document how to do it manually for these cases, but I think this default should cover most use cases.

@adobe-bot
Copy link

Build successful! 🎉

@devongovett devongovett marked this pull request as ready for review April 1, 2021 20:59
// and for React to re-render. If an insert occurs during this time, it will be selected/focused below.
// If items are not "immediately" inserted by the onDrop handler, the application will need to handle
// selecting and focusing those items themselves.
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

We need to save the timeout reference in case of unmount so we can cancel it

@adobe-bot
Copy link

Build successful! 🎉

@dannify dannify merged commit b1c3b3b into main Apr 15, 2021
@dannify dannify deleted the drop-focus branch April 15, 2021 17:10
majornista pushed a commit to majornista/react-spectrum-v3 that referenced this pull request May 19, 2021
* Update dnd examples to focus inserted items on drop

* Automatically focus and select items on drop

* Review changes
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.

None yet

6 participants