provided.innerRef(ref)}
+ ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
@@ -104,18 +105,17 @@ const getDispatchPropsStub = (): DispatchProps => ({
dropAnimationFinished: jest.fn(),
});
-// $ExpectError - not setting children function
const defaultOwnProps: OwnProps = {
draggableId,
+ index: 0,
isDragDisabled: false,
- type,
+ disableInteractiveElementBlocking: false,
+ children: () => null,
};
-// $ExpectError - not setting children function
const disabledOwnProps: OwnProps = {
- draggableId,
+ ...defaultOwnProps,
isDragDisabled: true,
- type,
};
const defaultMapProps: MapProps = {
@@ -255,7 +255,13 @@ const getStubber = stub =>
const snapshot: StateSnapshot = this.props.snapshot;
stub({ provided, snapshot });
return (
-
+
+ Drag me!
+
);
}
};
@@ -266,6 +272,32 @@ const customViewport: Viewport = {
subject: getArea({ top: 200, left: 100, right: 300, bottom: 300 }),
};
+const looseFocus = (wrapper: ReactWrapper) => {
+ const el: HTMLElement = wrapper.getDOMNode();
+ // raw event
+ el.blur();
+ // let the wrapper know about it
+ wrapper.simulate('blur');
+};
+class WithNestedHandle extends Component<{ provided: Provided }> {
+ render() {
+ const provided: Provided = this.props.provided;
+ return (
+
+
+ Cannot drag by me
+
+
+ Can drag by me
+
+
+ );
+ }
+}
+
describe('Draggable - unconnected', () => {
beforeAll(() => {
requestAnimationFrame.reset();
@@ -303,7 +335,7 @@ describe('Draggable - unconnected', () => {
});
const provided: Provided = getLastCall(myMock)[0].provided;
- expect(provided.draggableProps['data-react-beautiful-dnd-draggable']).toEqual(styleMarshal.styleContext);
+ expect(provided.draggableProps[attributes.draggable]).toEqual(styleMarshal.styleContext);
});
describe('drag handle', () => {
@@ -341,25 +373,6 @@ describe('Draggable - unconnected', () => {
});
describe('non standard drag handle', () => {
- class WithNestedHandle extends Component<{ provided: Provided }> {
- render() {
- const provided: Provided = this.props.provided;
- return (
-
provided.innerRef(ref)}
- {...provided.draggableProps}
- >
-
- Cannot drag by me
-
-
- Can drag by me
-
-
- );
- }
- }
-
it('should allow the ability to have the drag handle to be a child of the draggable', () => {
const dispatchProps: DispatchProps = getDispatchPropsStub();
managedWrapper = mountDraggable({
@@ -1367,7 +1380,10 @@ describe('Draggable - unconnected', () => {
});
});
- describe('Portal usage', () => {
+ // This is covered in focus-management.spec
+ // But I have included in here also to ensure that the entire
+ // consumer experience is tested (this is how a consumer would use it)
+ describe('Portal usage (Draggable consumer)', () => {
const body: ?HTMLElement = document.body;
if (!body) {
throw new Error('Portal test requires document.body to be present');
@@ -1456,6 +1472,9 @@ describe('Draggable - unconnected', () => {
expect(latest).not.toBe(original);
// no longer in a portal
expect(latest).not.toBe(wrapper.find(WithPortal).instance().portal);
+
+ // cleanup
+ looseFocus(wrapper);
});
it('should not take focus if moving to a portal and did not previously have focus', () => {
diff --git a/test/unit/view/unconnected-droppable.spec.js b/test/unit/view/unconnected-droppable.spec.js
index 0005a6001d..6b5883cfca 100644
--- a/test/unit/view/unconnected-droppable.spec.js
+++ b/test/unit/view/unconnected-droppable.spec.js
@@ -27,7 +27,12 @@ const getStubber = (mock: Function) =>
snapshot: this.props.snapshot,
});
return (
-
Hey there
+
+ Hey there
+
);
}
};
diff --git a/website/src/components/examples/board/board.jsx b/website/src/components/examples/board/board.jsx
index 132a15cf26..61547f33d9 100644
--- a/website/src/components/examples/board/board.jsx
+++ b/website/src/components/examples/board/board.jsx
@@ -40,7 +40,6 @@ type Props = {|
type State = {|
columns: QuoteMap,
ordered: string[],
- autoFocusQuoteId: ?string,
|}
export default class Board extends Component
{
@@ -49,7 +48,6 @@ export default class Board extends Component {
state: State = {
columns: this.props.initial,
ordered: Object.keys(this.props.initial),
- autoFocusQuoteId: null,
}
boardRef: ?HTMLElement
@@ -65,10 +63,6 @@ export default class Board extends Component {
onDragStart = (initial: DragStart) => {
publishOnDragStart(initial);
-
- this.setState({
- autoFocusQuoteId: null,
- });
}
onDragEnd = (result: DropResult) => {
@@ -113,7 +107,6 @@ export default class Board extends Component {
this.setState({
columns: data.quoteMap,
- autoFocusQuoteId: data.autoFocusQuoteId,
});
}
@@ -137,7 +130,6 @@ export default class Board extends Component {
index={index}
title={key}
quotes={columns[key]}
- autoFocusQuoteId={this.state.autoFocusQuoteId}
/>
))}
diff --git a/website/src/components/examples/board/column.jsx b/website/src/components/examples/board/column.jsx
index 62eb31ea6e..7c8bec5ac3 100644
--- a/website/src/components/examples/board/column.jsx
+++ b/website/src/components/examples/board/column.jsx
@@ -32,7 +32,6 @@ type Props = {|
title: string,
quotes: Quote[],
index: number,
- autoFocusQuoteId: ?string,
|}
export default class Column extends Component {
@@ -59,7 +58,6 @@ export default class Column extends Component {
listId={title}
listType="QUOTE"
quotes={quotes}
- autoFocusQuoteId={this.props.autoFocusQuoteId}
/>
)}
diff --git a/website/src/components/examples/multiple-horizontal/quote-app.jsx b/website/src/components/examples/multiple-horizontal/quote-app.jsx
index 76fa42856d..af8e35563b 100644
--- a/website/src/components/examples/multiple-horizontal/quote-app.jsx
+++ b/website/src/components/examples/multiple-horizontal/quote-app.jsx
@@ -36,7 +36,6 @@ export default class QuoteApp extends Component {
state: State = {
quoteMap: this.props.initial,
- autoFocusQuoteId: null,
}
onDragStart = (initial: DragStart) => {
@@ -61,7 +60,7 @@ export default class QuoteApp extends Component {
}
render() {
- const { quoteMap, autoFocusQuoteId } = this.state;
+ const { quoteMap } = this.state;
return (
{
listId={key}
listType="CARD"
quotes={quoteMap[key]}
- autoFocusQuoteId={autoFocusQuoteId}
/>
))}
diff --git a/website/src/components/examples/multiple-vertical/quote-app.jsx b/website/src/components/examples/multiple-vertical/quote-app.jsx
index 28bc931b66..0b84087162 100644
--- a/website/src/components/examples/multiple-vertical/quote-app.jsx
+++ b/website/src/components/examples/multiple-vertical/quote-app.jsx
@@ -70,7 +70,6 @@ export default class QuoteApp extends Component {
state: State = {
quoteMap: this.props.initial,
- autoFocusQuoteId: null,
}
onDragStart = (initial: DragStart) => {
@@ -114,7 +113,7 @@ export default class QuoteApp extends Component {
}
render() {
- const { quoteMap, autoFocusQuoteId } = this.state;
+ const { quoteMap } = this.state;
const disabledDroppable = 'TODO';
return (
@@ -131,7 +130,6 @@ export default class QuoteApp extends Component {
listType="card"
isDropDisabled={disabledDroppable === 'alpha'}
quotes={quoteMap.alpha}
- autoFocusQuoteId={autoFocusQuoteId}
/>
@@ -141,7 +139,6 @@ export default class QuoteApp extends Component {
listType="card"
isDropDisabled={disabledDroppable === 'beta'}
quotes={quoteMap.beta}
- autoFocusQuoteId={autoFocusQuoteId}
/>
@@ -151,7 +148,6 @@ export default class QuoteApp extends Component {
listType="card"
isDropDisabled={disabledDroppable === 'gamma'}
quotes={quoteMap.gamma}
- autoFocusQuoteId={autoFocusQuoteId}
/>
@@ -163,7 +159,6 @@ export default class QuoteApp extends Component {
listType="card"
isDropDisabled={disabledDroppable === 'delta'}
quotes={quoteMap.delta}
- autoFocusQuoteId={autoFocusQuoteId}
/>
{
internalScroll
isDropDisabled={disabledDroppable === 'epsilon'}
quotes={quoteMap.epsilon}
- autoFocusQuoteId={autoFocusQuoteId}
/>
@@ -183,7 +177,6 @@ export default class QuoteApp extends Component {
listType="card"
isDropDisabled={disabledDroppable === 'zeta'}
quotes={quoteMap.zeta}
- autoFocusQuoteId={autoFocusQuoteId}
/>
@@ -193,7 +186,6 @@ export default class QuoteApp extends Component {
listType="card"
isDropDisabled={disabledDroppable === 'eta'}
quotes={quoteMap.eta}
- autoFocusQuoteId={autoFocusQuoteId}
/>
@@ -203,7 +195,6 @@ export default class QuoteApp extends Component {
listType="card"
isDropDisabled={disabledDroppable === 'theta'}
quotes={quoteMap.theta}
- autoFocusQuoteId={autoFocusQuoteId}
/>
@@ -214,7 +205,6 @@ export default class QuoteApp extends Component {
listType="card"
isDropDisabled={disabledDroppable === 'iota'}
quotes={quoteMap.iota}
- autoFocusQuoteId={autoFocusQuoteId}
/>
@@ -225,7 +215,6 @@ export default class QuoteApp extends Component {
internalScroll
isDropDisabled={disabledDroppable === 'kappa'}
quotes={quoteMap.kappa}
- autoFocusQuoteId={autoFocusQuoteId}
/>
diff --git a/website/src/components/examples/primatives/author-item.jsx b/website/src/components/examples/primatives/author-item.jsx
index ad5e123baf..a02739260a 100644
--- a/website/src/components/examples/primatives/author-item.jsx
+++ b/website/src/components/examples/primatives/author-item.jsx
@@ -31,19 +31,9 @@ type Props = {|
author: Author,
provided: DraggableProvided,
snapshot: DraggableStateSnapshot,
- autoFocus?: boolean,
|}
export default class AuthorItem extends Component {
- componentDidMount() {
- if (!this.props.autoFocus) {
- return;
- }
-
- // eslint-disable-next-line react/no-find-dom-node
- const node: HTMLElement = ReactDOM.findDOMNode(this);
- node.focus();
- }
render() {
const author: Author = this.props.author;
diff --git a/website/src/components/examples/primatives/author-list.jsx b/website/src/components/examples/primatives/author-list.jsx
index 282ece6efa..31b09c00c3 100644
--- a/website/src/components/examples/primatives/author-list.jsx
+++ b/website/src/components/examples/primatives/author-list.jsx
@@ -53,7 +53,6 @@ type Props = {|
listId: string,
listType?: string,
internalScroll?: boolean,
- autoFocusQuoteId?: ?string,
|}
export default class AuthorList extends Component {
@@ -75,7 +74,6 @@ export default class AuthorList extends Component {
author={quote.author}
provided={dragProvided}
snapshot={dragSnapshot}
- autoFocus={this.props.autoFocusQuoteId === quote.id}
/>
)}
diff --git a/website/src/components/examples/primatives/quote-item.jsx b/website/src/components/examples/primatives/quote-item.jsx
index 141628c64b..393c31044c 100644
--- a/website/src/components/examples/primatives/quote-item.jsx
+++ b/website/src/components/examples/primatives/quote-item.jsx
@@ -10,7 +10,6 @@ type Props = {
quote: Quote,
isDragging: boolean,
provided: DraggableProvided,
- autoFocus?: boolean,
}
const Container = styled.a`
@@ -99,16 +98,6 @@ flex-grow: 1;
// things we should be doing in the selector as we do not know if consumers
// will be using PureComponent
export default class QuoteItem extends React.PureComponent {
- componentDidMount() {
- if (!this.props.autoFocus) {
- return;
- }
-
- // eslint-disable-next-line react/no-find-dom-node
- const node: HTMLElement = (ReactDOM.findDOMNode(this) : any);
- node.focus();
- }
-
render() {
const { quote, isDragging, provided } = this.props;
diff --git a/website/src/components/examples/primatives/quote-list.jsx b/website/src/components/examples/primatives/quote-list.jsx
index d0475e43e0..cf28d6be5f 100644
--- a/website/src/components/examples/primatives/quote-list.jsx
+++ b/website/src/components/examples/primatives/quote-list.jsx
@@ -50,13 +50,11 @@ type Props = {|
isDropDisabled ?: boolean,
style?: Object,
// may not be provided - and might be null
- autoFocusQuoteId?: ?string,
ignoreContainerClipping?: boolean,
|}
type QuoteListProps = {|
quotes: Quote[],
- autoFocusQuoteId: ?string,
|}
class InnerQuoteList extends Component {
@@ -79,7 +77,6 @@ class InnerQuoteList extends Component {
quote={quote}
isDragging={dragSnapshot.isDragging}
provided={dragProvided}
- autoFocus={this.props.autoFocusQuoteId === quote.id}
/>
)}
@@ -93,12 +90,11 @@ type InnerListProps = {|
dropProvided: DroppableProvided,
quotes: Quote[],
title: ?string,
- autoFocusQuoteId: ?string,
|}
class InnerList extends Component {
render() {
- const { quotes, dropProvided, autoFocusQuoteId } = this.props;
+ const { quotes, dropProvided } = this.props;
const title = this.props.title ? (
{this.props.title}
) : null;
@@ -109,7 +105,6 @@ class InnerList extends Component {
{dropProvided.placeholder}
@@ -128,7 +123,6 @@ export default class QuoteList extends Component {
listType,
style,
quotes,
- autoFocusQuoteId,
title,
} = this.props;
@@ -152,7 +146,6 @@ export default class QuoteList extends Component {
quotes={quotes}
title={title}
dropProvided={dropProvided}
- autoFocusQuoteId={autoFocusQuoteId}
/>
) : (
@@ -160,7 +153,6 @@ export default class QuoteList extends Component {
quotes={quotes}
title={title}
dropProvided={dropProvided}
- autoFocusQuoteId={autoFocusQuoteId}
/>
)}
diff --git a/website/src/components/examples/reorder.js b/website/src/components/examples/reorder.js
index 2525127c81..87309cd76f 100644
--- a/website/src/components/examples/reorder.js
+++ b/website/src/components/examples/reorder.js
@@ -24,7 +24,6 @@ type ReorderQuoteMapArgs = {|
export type ReorderQuoteMapResult = {|
quoteMap: QuoteMap,
- autoFocusQuoteId: ?string,
|}
export const reorderQuoteMap = ({
@@ -49,8 +48,6 @@ export const reorderQuoteMap = ({
};
return {
quoteMap: result,
- // not auto focusing in own list
- autoFocusQuoteId: null,
};
}
@@ -69,6 +66,5 @@ export const reorderQuoteMap = ({
return {
quoteMap: result,
- autoFocusQuoteId: target.id,
};
};