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

addressing feedback from michael #458

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,12 @@ To get around this you can use [`React.Portal`](https://reactjs.org/docs/portals

##### Focus retention when moving between lists

When moving a `Draggable` from one list to another the default browser behaviour is for the *drag handle* element to loose focus. This is because the old element is being destroyed and a new one is being created. The loss of focus is not good when dragging with a keyboard as the user is then unable to continue to interact with the element. To improve this user experience we give a *drag handle* focus as it mounts if it had browser focus when it unmounted and nothing else has obtained browser focus.
When moving a `Draggable` from one list to another the default browser behaviour is for the *drag handle* element to loose focus. This is because the old element is being destroyed and a new one is being created. The loss of focus is not good when dragging with a keyboard as the user is then unable to continue to interact with the element. To improve this user experience we automatically give a *drag handle* focus when:

- It was unmounted at the end of a drag
- It had focus
- It is enabled when mounted
- No other elements have gained browser focus before the drag handle has mounted

##### Extending `DraggableProps.style`

Expand Down
2 changes: 1 addition & 1 deletion src/view/drag-handle/drag-handle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class DragHandle extends Component<Props> {
this.lastDraggableRef = ref;

// After a ref change we might need to manually force focus onto the ref.
// When moving something into or out of a portal the element looses focus
// When moving something into or out of a portal the element loses focus
// https://github.com/facebook/react/issues/12454

// No need to focus
Expand Down
2 changes: 1 addition & 1 deletion src/view/drag-handle/util/focus-retainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const tryRestoreFocus = (id: DraggableId, draggableRef: HTMLElement) => {
return;
}

// We are about to force force onto a drag handle
// We are about to force focus onto a drag handle

retainingFocusFor = null;
// no need to clear it - we are already clearing it
Expand Down
4 changes: 2 additions & 2 deletions test/unit/view/unconnected-draggable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ const customViewport: Viewport = {
subject: getArea({ top: 200, left: 100, right: 300, bottom: 300 }),
};

const looseFocus = (wrapper: ReactWrapper) => {
const loseFocus = (wrapper: ReactWrapper) => {
const el: HTMLElement = wrapper.getDOMNode();
// raw event
el.blur();
Expand Down Expand Up @@ -1474,7 +1474,7 @@ describe('Draggable - unconnected', () => {
expect(latest).not.toBe(wrapper.find(WithPortal).instance().portal);

// cleanup
looseFocus(wrapper);
loseFocus(wrapper);
});

it('should not take focus if moving to a portal and did not previously have focus', () => {
Expand Down