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

Fix bug with window scroll container #806

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/.stories/Storybook.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ $focusedOutlineColor: #4c9ffe;
align-items: center;
}

.rootAutoHeight {
height: auto;
}

// Base styles
.list {
width: 400px;
Expand Down Expand Up @@ -122,6 +126,10 @@ $focusedOutlineColor: #4c9ffe;
background-color: transparent;
}

.gridAutoHeight {
height: auto;
}

.gridItem {
width: 130px;
height: 130px;
Expand Down
55 changes: 34 additions & 21 deletions src/.stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,22 +438,20 @@ const ShrinkingSortableList = SortableContainer(
},
);

const NestedSortableList = SortableContainer(
({className, items, isSorting}) => {
return (
<div className={className}>
{items.map((value, index) => (
<Category
tabbable
key={`category-${value}`}
index={index}
value={value}
/>
))}
</div>
);
},
);
const NestedSortableList = SortableContainer(({className, items}) => {
return (
<div className={className}>
{items.map((value, index) => (
<Category
tabbable
key={`category-${value}`}
index={index}
value={value}
/>
))}
</div>
);
});

storiesOf('General | Layout / Vertical list', module)
.add('Basic setup', () => {
Expand Down Expand Up @@ -515,11 +513,6 @@ storiesOf('General | Layout / Horizontal list', module).add(

storiesOf('General | Layout / Grid', module)
.add('Basic setup', () => {
const transformOrigin = {
x: 0,
y: 0,
};

return (
<div className={style.root}>
<ListWrapper
Expand Down Expand Up @@ -597,6 +590,26 @@ storiesOf('General | Layout / Grid', module)
/>
</div>
);
})
.add('Window as scroll container', () => {
return (
<div className={classNames(style.root, style.rootAutoHeight)}>
<ListWrapper
component={SortableList}
axis={'xy'}
items={getItems(40, false)}
helperClass={style.stylizedHelper}
useWindowAsScrollContainer
className={classNames(
style.list,
style.stylizedList,
style.grid,
style.gridAutoHeight,
)}
itemClass={classNames(style.stylizedItem, style.gridItem)}
/>
</div>
);
});

storiesOf('General | Configuration / Options', module)
Expand Down
10 changes: 8 additions & 2 deletions src/SortableContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ export default function sortableContainer(
const margin = getElementMargin(node);
const gridGap = getContainerGridGap(this.container);
const containerBoundingRect = this.scrollContainer.getBoundingClientRect();

// Need for correct sorting behavior in grid layout with enabled `useWindowAsScrollContainer`
if (useWindowAsScrollContainer) {
containerBoundingRect.width = this.container.clientWidth;
}

const dimensions = getHelperDimensions({index, node, collection});

this.node = node;
Expand Down Expand Up @@ -645,9 +651,9 @@ export default function sortableContainer(

// For keyboard sorting, we want user input to dictate the position of the nodes
const mustShiftBackward =
isKeySorting && (index > this.index && index <= prevIndex);
isKeySorting && index > this.index && index <= prevIndex;
const mustShiftForward =
isKeySorting && (index < this.index && index >= prevIndex);
isKeySorting && index < this.index && index >= prevIndex;

const translate = {
x: 0,
Expand Down