Skip to content

Commit 5043e09

Browse files
authored
Merge branch 'master' into keyboard-sorting
2 parents b943c05 + dd3151f commit 5043e09

File tree

11 files changed

+273
-71
lines changed

11 files changed

+273
-71
lines changed

CHANGELOG.md

+48-20
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,63 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5-
<a name="1.8.0"></a>
6-
# [1.8.0](https://github.com/clauderic/react-sortable-hoc/compare/v1.1.0...v1.8.0) (2019-03-18)
5+
<a name="1.8.3"></a>
76

7+
## [1.8.3](https://github.com/clauderic/react-sortable-hoc/compare/v1.8.2...v1.8.3) (2019-03-20)
88

99
### Bug Fixes
1010

11-
* added prop-types to peerDependencies ([0e855c5](https://github.com/clauderic/react-sortable-hoc/commit/0e855c5))
12-
* copy canvas content into cloned node ([43ad122](https://github.com/clauderic/react-sortable-hoc/commit/43ad122))
13-
* get updated index after updateBeforeSortStart ([4471a0a](https://github.com/clauderic/react-sortable-hoc/commit/4471a0a))
14-
* helperContainer PropType definition broke server-side rendering ([#471](https://github.com/clauderic/react-sortable-hoc/issues/471)) ([c0eef97](https://github.com/clauderic/react-sortable-hoc/commit/c0eef97))
15-
* invalid helperContainer PropType definition ([#493](https://github.com/clauderic/react-sortable-hoc/issues/493)) ([dc1d18f](https://github.com/clauderic/react-sortable-hoc/commit/dc1d18f))
16-
* lock axis story should not use lockToContainerEdges ([db1d3a9](https://github.com/clauderic/react-sortable-hoc/commit/db1d3a9))
17-
* omit disableAutoscroll prop ([#502](https://github.com/clauderic/react-sortable-hoc/issues/502)) ([e994e73](https://github.com/clauderic/react-sortable-hoc/commit/e994e73))
18-
* omit spreading helperContainer prop ([#497](https://github.com/clauderic/react-sortable-hoc/issues/497)) ([12bafdf](https://github.com/clauderic/react-sortable-hoc/commit/12bafdf))
19-
* overflow bug while dragging an item upwards in a grid ([1a2c87e](https://github.com/clauderic/react-sortable-hoc/commit/1a2c87e))
20-
* replace process.env.NODE_ENV in UMD builds ([16135df](https://github.com/clauderic/react-sortable-hoc/commit/16135df))
21-
* update helperContainer prop type definition ([#491](https://github.com/clauderic/react-sortable-hoc/issues/491)) ([fd30383](https://github.com/clauderic/react-sortable-hoc/commit/fd30383))
22-
* updated the behaviour of disabled elements ([bd3d041](https://github.com/clauderic/react-sortable-hoc/commit/bd3d041))
23-
* virtualized collection grid bug ([a57975c](https://github.com/clauderic/react-sortable-hoc/commit/a57975c))
24-
11+
- issue with windowAsScrollContainer and translation offsets ([0391e62](https://github.com/clauderic/react-sortable-hoc/commit/0391e62))
2512

2613
### Features
2714

28-
* Add disableAutoscroll prop ([#484](https://github.com/clauderic/react-sortable-hoc/issues/484)) ([7845e76](https://github.com/clauderic/react-sortable-hoc/commit/7845e76))
29-
* added helperContainer prop ([286eff4](https://github.com/clauderic/react-sortable-hoc/commit/286eff4))
30-
* allow helperContainer prop to be a function returning an HTMLElement ([#489](https://github.com/clauderic/react-sortable-hoc/issues/489)) ([f4a9b4a](https://github.com/clauderic/react-sortable-hoc/commit/f4a9b4a))
31-
* Detect scroll container automatically ([#507](https://github.com/clauderic/react-sortable-hoc/issues/507)) ([6572921](https://github.com/clauderic/react-sortable-hoc/commit/6572921))
15+
- Add disableAutoscroll prop ([#484](https://github.com/clauderic/react-sortable-hoc/issues/484)) ([7845e76](https://github.com/clauderic/react-sortable-hoc/commit/7845e76))
16+
- added helperContainer prop ([286eff4](https://github.com/clauderic/react-sortable-hoc/commit/286eff4))
17+
- allow helperContainer prop to be a function returning an HTMLElement ([#489](https://github.com/clauderic/react-sortable-hoc/issues/489)) ([f4a9b4a](https://github.com/clauderic/react-sortable-hoc/commit/f4a9b4a))
18+
- Detect scroll container automatically ([#507](https://github.com/clauderic/react-sortable-hoc/issues/507)) ([6572921](https://github.com/clauderic/react-sortable-hoc/commit/6572921))
19+
20+
<a name="1.8.2"></a>
21+
22+
## [1.8.2](https://github.com/clauderic/react-sortable-hoc/compare/v1.8.1...v1.8.2) (2019-03-19)
23+
24+
### Bug Fixes
25+
26+
- issue with getComputedStyle and getScrollingParent ([b104249](https://github.com/clauderic/react-sortable-hoc/commit/b104249))
27+
28+
<a name="1.8.1"></a>
29+
30+
## [1.8.1](https://github.com/clauderic/react-sortable-hoc/compare/v1.8.0...v1.8.1) (2019-03-18)
31+
32+
### Bug Fixes
33+
34+
- issue with cloning canvas context of dragged items ([#512](https://github.com/clauderic/react-sortable-hoc/issues/512)) ([4df34ad](https://github.com/clauderic/react-sortable-hoc/commit/4df34ad))
35+
36+
<a name="1.8.0"></a>
37+
38+
# [1.8.0](https://github.com/clauderic/react-sortable-hoc/compare/v1.1.0...v1.8.0) (2019-03-18)
39+
40+
### Bug Fixes
41+
42+
- added prop-types to peerDependencies ([0e855c5](https://github.com/clauderic/react-sortable-hoc/commit/0e855c5))
43+
- copy canvas content into cloned node ([43ad122](https://github.com/clauderic/react-sortable-hoc/commit/43ad122))
44+
- get updated index after updateBeforeSortStart ([4471a0a](https://github.com/clauderic/react-sortable-hoc/commit/4471a0a))
45+
- helperContainer PropType definition broke server-side rendering ([#471](https://github.com/clauderic/react-sortable-hoc/issues/471)) ([c0eef97](https://github.com/clauderic/react-sortable-hoc/commit/c0eef97))
46+
- invalid helperContainer PropType definition ([#493](https://github.com/clauderic/react-sortable-hoc/issues/493)) ([dc1d18f](https://github.com/clauderic/react-sortable-hoc/commit/dc1d18f))
47+
- lock axis story should not use lockToContainerEdges ([db1d3a9](https://github.com/clauderic/react-sortable-hoc/commit/db1d3a9))
48+
- omit disableAutoscroll prop ([#502](https://github.com/clauderic/react-sortable-hoc/issues/502)) ([e994e73](https://github.com/clauderic/react-sortable-hoc/commit/e994e73))
49+
- omit spreading helperContainer prop ([#497](https://github.com/clauderic/react-sortable-hoc/issues/497)) ([12bafdf](https://github.com/clauderic/react-sortable-hoc/commit/12bafdf))
50+
- overflow bug while dragging an item upwards in a grid ([1a2c87e](https://github.com/clauderic/react-sortable-hoc/commit/1a2c87e))
51+
- replace process.env.NODE_ENV in UMD builds ([16135df](https://github.com/clauderic/react-sortable-hoc/commit/16135df))
52+
- update helperContainer prop type definition ([#491](https://github.com/clauderic/react-sortable-hoc/issues/491)) ([fd30383](https://github.com/clauderic/react-sortable-hoc/commit/fd30383))
53+
- updated the behaviour of disabled elements ([bd3d041](https://github.com/clauderic/react-sortable-hoc/commit/bd3d041))
54+
- virtualized collection grid bug ([a57975c](https://github.com/clauderic/react-sortable-hoc/commit/a57975c))
3255

56+
### Features
3357

58+
- Add disableAutoscroll prop ([#484](https://github.com/clauderic/react-sortable-hoc/issues/484)) ([7845e76](https://github.com/clauderic/react-sortable-hoc/commit/7845e76))
59+
- added helperContainer prop ([286eff4](https://github.com/clauderic/react-sortable-hoc/commit/286eff4))
60+
- allow helperContainer prop to be a function returning an HTMLElement ([#489](https://github.com/clauderic/react-sortable-hoc/issues/489)) ([f4a9b4a](https://github.com/clauderic/react-sortable-hoc/commit/f4a9b4a))
61+
- Detect scroll container automatically ([#507](https://github.com/clauderic/react-sortable-hoc/issues/507)) ([6572921](https://github.com/clauderic/react-sortable-hoc/commit/6572921))
3462

3563
<a name="1.7.1"></a>
3664

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-sortable-hoc",
3-
"version": "1.8.0",
3+
"version": "1.8.3",
44
"description": "Set of higher-order components to turn any list into a sortable, touch-friendly, animated list",
55
"author": {
66
"name": "Clauderic Demers",

src/.stories/index.js

+8-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import random from 'lodash/random';
1515
import classNames from 'classnames';
1616

1717
import GroupedItems from './grouping-items';
18+
import InteractiveElements from './interactive-elements-stress-test';
1819

1920
function getItems(count, height) {
2021
var heights = [65, 110, 140, 65, 90, 65];
@@ -792,24 +793,11 @@ storiesOf('Advanced examples | Re-rendering before sorting', module)
792793
);
793794
});
794795

795-
storiesOf('Stress tests | Keyboard sorting', module)
796-
.add('Inputs', () => (
796+
storiesOf('Stress Testing | Nested elements', module).add(
797+
'Interactive elements',
798+
() => (
797799
<div className={style.root}>
798-
<ListWrapper
799-
component={SortableList}
800-
items={getItems(50, 59)}
801-
helperClass={style.stylizedHelper}
802-
type="input"
803-
/>
804-
</div>
805-
))
806-
.add('Links', () => (
807-
<div className={style.root}>
808-
<ListWrapper
809-
component={SortableList}
810-
items={getItems(50, 59)}
811-
helperClass={style.stylizedHelper}
812-
type="link"
813-
/>
814-
</div>
815-
));
800+
<InteractiveElements />
801+
</div>
802+
),
803+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import {sortableElement} from '../../../../src';
3+
4+
import styles from './Item.scss';
5+
6+
function Item(props) {
7+
const {children} = props;
8+
9+
return <div className={styles.root}>{children}</div>;
10+
}
11+
12+
export default sortableElement(Item);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
$color: #333;
2+
$white: #fff;
3+
$backgroundColor: $white;
4+
5+
$boxShadow: 0 5px 5px -5px rgba(0, 0, 0, 0.2);
6+
7+
$fontWeight-regular: 400;
8+
$fontWeight-bold: 600;
9+
10+
$borderRadius: 3px;
11+
$borderWidth: 1px;
12+
$borderColor: #efefef;
13+
14+
.root {
15+
display: block;
16+
width: 250px;
17+
padding: 20px;
18+
background-color: $backgroundColor;
19+
border-bottom: $borderWidth solid #efefef;
20+
box-sizing: border-box;
21+
user-select: none;
22+
23+
color: $color;
24+
font-family: sans-serif;
25+
font-weight: $fontWeight-regular;
26+
27+
> * {
28+
display: block;
29+
width: 100%;
30+
font-size: 14px;
31+
}
32+
33+
> input,
34+
> textarea {
35+
padding: 5px;
36+
border: 1px solid #e0e0e0;
37+
box-sizing: border-box;
38+
}
39+
40+
label {
41+
input {
42+
margin-right: 0.5em;
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Item from './Item';
2+
3+
export default Item;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import {sortableContainer} from '../../../src';
3+
4+
import Item from './Item';
5+
6+
function List({items}) {
7+
return (
8+
<div>
9+
{items.map(([key, children], index) => {
10+
return (
11+
<Item key={key} index={index}>
12+
{children}
13+
</Item>
14+
);
15+
})}
16+
</div>
17+
);
18+
}
19+
20+
export default sortableContainer(List);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React from 'react';
2+
import arrayMove from 'array-move';
3+
4+
import SortableList from './List';
5+
6+
const items = {
7+
input: <input placeholder="Regular text input" />,
8+
textarea: <textarea placeholder="Textarea input" />,
9+
select: (
10+
<select>
11+
<option>Option 1</option>
12+
<option>Option 2</option>
13+
<option>Option 3</option>
14+
</select>
15+
),
16+
checkbox: (
17+
<>
18+
<label>
19+
<input type="checkbox" name="checkbox" />
20+
Checkbox 1
21+
</label>
22+
<label>
23+
<input type="checkbox" name="checkbox" />
24+
Checkbox 2
25+
</label>
26+
</>
27+
),
28+
radio: (
29+
<>
30+
<label>
31+
<input type="radio" name="option" />
32+
Option 1
33+
</label>
34+
<label>
35+
<input type="radio" name="option" />
36+
Option 2
37+
</label>
38+
</>
39+
),
40+
range: <input type="range" min="1" max="100" />,
41+
contentEditable: (
42+
<div
43+
contentEditable
44+
dangerouslySetInnerHTML={{
45+
__html: 'Lorem ipsum <strong>dolor sit</strong> amet',
46+
}}
47+
/>
48+
),
49+
};
50+
51+
export default class InteractiveElements extends React.Component {
52+
state = {
53+
items: Object.entries(items),
54+
};
55+
56+
render() {
57+
return (
58+
<SortableList
59+
// The distance prop isn't strictly required for this example, but it is recommended
60+
// to set it to a low value for sortable items with nested interactive elements
61+
// such as clickable labels for checkbox / radio inputs
62+
distance={2}
63+
items={this.state.items}
64+
onSortEnd={this.onSortEnd}
65+
/>
66+
);
67+
}
68+
69+
onSortEnd = ({oldIndex, newIndex}) => {
70+
if (oldIndex === newIndex) {
71+
return;
72+
}
73+
74+
this.setState(({items}) => ({
75+
items: arrayMove(items, oldIndex, newIndex),
76+
}));
77+
};
78+
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import {NodeType} from '../utils';
1+
import {NodeType, closest} from '../utils';
22

33
export default function defaultShouldCancelStart(event) {
44
// Cancel sorting if the event target is an `input`, `textarea`, `select` or `option`
5-
const disabledElements = [
5+
const interactiveElements = [
66
NodeType.Input,
77
NodeType.Textarea,
88
NodeType.Select,
99
NodeType.Option,
1010
NodeType.Button,
1111
];
1212

13-
if (disabledElements.indexOf(event.target.tagName) !== -1) {
13+
if (interactiveElements.indexOf(event.target.tagName) !== -1) {
1414
// Return true to cancel sorting
1515
return true;
1616
}
1717

18+
if (closest(event.target, (el) => el.contentEditable === 'true')) {
19+
return true;
20+
}
21+
1822
return false;
1923
}

0 commit comments

Comments
 (0)