Skip to content

Commit cc1f4ca

Browse files
author
Clauderic Demers
committed
tweak: extract node types into enum
1 parent 1b77dcd commit cc1f4ca

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/SortableContainer/defaultShouldCancelStart.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
import {NodeType} from '../utils';
2+
13
export default function defaultShouldCancelStart(event) {
24
// Cancel sorting if the event target is an `input`, `textarea`, `select` or `option`
3-
const disabledElements = ['input', 'textarea', 'select', 'option', 'button'];
5+
const disabledElements = [
6+
NodeType.Input,
7+
NodeType.Textarea,
8+
NodeType.Select,
9+
NodeType.Option,
10+
NodeType.Button,
11+
];
412

5-
if (disabledElements.indexOf(event.target.tagName.toLowerCase()) !== -1) {
13+
if (disabledElements.indexOf(event.target.tagName) !== -1) {
614
// Return true to cancel sorting
715
return true;
816
}

src/SortableContainer/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getPosition,
1717
isTouchEvent,
1818
limit,
19+
NodeType,
1920
omit,
2021
provideDisplayName,
2122
setInlineStyles,
@@ -140,10 +141,7 @@ export default function sortableContainer(
140141
* prevent subsequent 'mousemove' events from being fired
141142
* (see https://github.com/clauderic/react-sortable-hoc/issues/118)
142143
*/
143-
if (
144-
!isTouchEvent(event) &&
145-
event.target.tagName.toLowerCase() === 'a'
146-
) {
144+
if (!isTouchEvent(event) && event.target.tagName === NodeType.Anchor) {
147145
event.preventDefault();
148146
}
149147

src/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,13 @@ export function getScrollingParent(el) {
239239
return getScrollingParent(el.parentNode);
240240
}
241241
}
242+
243+
export const NodeType = {
244+
Anchor: 'A',
245+
Button: 'BUTTON',
246+
Canvas: 'CANVAS',
247+
Input: 'INPUT',
248+
Option: 'OPTION',
249+
Textarea: 'TEXTAREA',
250+
Select: 'SELECT',
251+
};

0 commit comments

Comments
 (0)