Skip to content
This repository was archived by the owner on Apr 1, 2021. It is now read-only.

Commit bc63285

Browse files
authored
Merge pull request #34 from canalplus/bug_find_start_id
wrapper is counted when finding start id element
2 parents 1ab23f0 + 91a29d8 commit bc63285

5 files changed

Lines changed: 85 additions & 28 deletions

File tree

dev/dev.jsx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {connect, Provider} from 'react-redux';
55
import {Binder, StrapeBinder, keysInit, keysReducer, activeKeyBinder} from '../src';
66

77
const logger = store => next => action => {
8-
console.group(action.type);
9-
console.info('dispatching', action);
8+
// console.group(action.type);
9+
// console.info('dispatching', action);
1010
const result = next(action);
11-
console.info('next state', store.getState());
12-
console.groupEnd(action.type);
11+
// console.info('next state', store.getState());
12+
// console.groupEnd(action.type);
1313
return result;
1414
};
1515

@@ -22,32 +22,48 @@ keysInit({store: store});
2222
const PureMosaic = ({binder1, binder2}) => {
2323
const selectedId1 = binder1.selectedId;
2424
const active1 = binder1.active;
25+
const binder1Style = {
26+
marginLeft: -binder1.marginLeft,
27+
};
2528
const selectedId2 = binder2.selectedId;
2629
const active2 = binder2.active;
30+
const binder2Style = {
31+
marginLeft: -binder2.marginLeft,
32+
};
2733
return (
28-
<div>
29-
<Binder id="binder1" active={true} onDownExit="binder2">
30-
<ul>
31-
<li id="b1" className={active1 && selectedId1 === 'b1' ? 'selected' : ''}>BOUTON 1</li>
32-
<li id="b2" className={active1 && selectedId1 === 'b2' ? 'selected' : ''}>BOUTON 2</li>
33-
<li id="b3" className={active1 && selectedId1 === 'b3' ? 'selected' : ''}>BOUTON 3</li>
34-
</ul>
35-
</Binder>
36-
<StrapeBinder id="binder2" onUpExit="binder1" exitStrategy="start">
37-
<ul>
38-
<li id="b4" className={active2 && selectedId2 === 'b4' ? 'selected' : ''}>BOUTON 4</li>
39-
<li id="b5" className={active2 && selectedId2 === 'b5' ? 'selected' : ''}>BOUTON 5</li>
40-
<li id="b6" className={active2 && selectedId2 === 'b6' ? 'selected' : ''}>BOUTON 6</li>
41-
</ul>
34+
<div className="container">
35+
<StrapeBinder id="binder1" onDownExit="binder2" exitStrategy="start" active={true}
36+
wrapper=".wrapper">
37+
<div className="wrapper">
38+
<ul style={binder1Style}>
39+
<li id="b1" className={active1 && selectedId1 === 'b1' ? 'selected' : ''}>BOUTON 1</li>
40+
<li id="b2" className={active1 && selectedId1 === 'b2' ? 'selected' : ''}>BOUTON 2</li>
41+
<li id="b3" className={active1 && selectedId1 === 'b3' ? 'selected' : ''}>BOUTON 3</li>
42+
<li id="b4" className={active1 && selectedId1 === 'b4' ? 'selected' : ''}>BOUTON 4</li>
43+
<li id="b5" className={active1 && selectedId1 === 'b5' ? 'selected' : ''}>BOUTON 5</li>
44+
<li id="b6" className={active1 && selectedId1 === 'b6' ? 'selected' : ''}>BOUTON 6</li>
45+
</ul>
46+
</div>
47+
</StrapeBinder>
48+
<StrapeBinder id="binder2" onUpExit="binder1" exitStrategy="start" wrapper=".wrapper">
49+
<div className="wrapper">
50+
<ul style={binder2Style}>
51+
<li id="b7" className={active2 && selectedId2 === 'b7' ? 'selected' : ''}>BOUTON 7</li>
52+
<li id="b8" className={active2 && selectedId2 === 'b8' ? 'selected' : ''}>BOUTON 8</li>
53+
<li id="b9" className={active2 && selectedId2 === 'b9' ? 'selected' : ''}>BOUTON 9</li>
54+
<li id="b10" className={active2 && selectedId2 === 'b10' ? 'selected' : ''}>BOUTON 10
55+
</li>
56+
<li id="b11" className={active2 && selectedId2 === 'b11' ? 'selected' : ''}>BOUTON 11
57+
</li>
58+
<li id="b12" className={active2 && selectedId2 === 'b12' ? 'selected' : ''}>BOUTON 12
59+
</li>
60+
</ul>
61+
</div>
4262
</StrapeBinder>
4363
</div>
4464
);
4565
};
4666

47-
function onEnter(element) {
48-
alert('ELEMENT #' + element.id);
49-
}
50-
5167
const Mosaic = connect(state => {
5268
return {
5369
binder1: state['@@keys'].getBinder('binder1'),

dev/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@
55
<title>flipflop example</title>
66
<style>
77

8+
.container {
9+
width: 1080px;
10+
margin: auto;
11+
}
12+
13+
.wrapper {
14+
width: 1080px;
15+
overflow: hidden;
16+
}
17+
818
ul {
919
padding: 0px;
20+
width: 40000px;
1021
}
1122

1223
li {

src/engines/strape.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ export function findMirrorExitId(leftElement, children) {
1515
return nextFocusedId[0].id;
1616
}
1717

18-
export function findStartExitId(children) {
18+
export function findStartExitId(children, dom) {
19+
const leftContainer = dom.getBoundingClientRect().left;
1920
const nextFocusedId = children
2021
.map(el => {
2122
return {
2223
id: el.id,
23-
left: el.getBoundingClientRect().left,
24+
left: el.getBoundingClientRect().left - leftContainer,
2425
};
2526
})
2627
.filter(el => el.left > 0)

src/redux/actions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ export function _updateBinderState(binderId, binderState) {
7373
}
7474
}
7575

76-
export function exitStrape(strategy, callback, nextElId, children) {
76+
export function exitStrape(strategy, callback, nextElId, children, dom) {
7777
switch (strategy) {
7878
case EXIT_STRATEGY_MIRROR:
7979
const leftElement = document.getElementById(nextElId);
8080
const mirrorId = findMirrorExitId(leftElement, children);
8181
_activeKeyBinder(callback, mirrorId, true);
8282
break;
8383
case EXIT_STRATEGY_START:
84-
const startId = findStartExitId(children);
84+
const startId = findStartExitId(children, dom);
8585
_activeKeyBinder(callback, startId, true);
8686
break;
8787
case EXIT_STRATEGY_MEMORY:
@@ -113,7 +113,7 @@ export function exit(strategy, callback, nextElId) {
113113
} else {
114114
const dom = document.getElementById(callback) || document;
115115
const children = [].slice.call(dom.querySelectorAll(nextBinderState.wChildren));
116-
exitStrape(strategy, callback, nextElId, children);
116+
exitStrape(strategy, callback, nextElId, children, dom);
117117
}
118118
} else {
119119
callback();

test/engines/strape.spec.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,35 @@ describe('engine/strape.js', () => {
8282
});
8383
describe('findStartExitId', () => {
8484
it('should return closed element to 0 left', () => {
85+
const wrapper = {
86+
getBoundingClientRect: () => {
87+
return {left: 0};
88+
},
89+
};
90+
const children = [{
91+
id: 1,
92+
getBoundingClientRect: () => {
93+
return {left: -10};
94+
},
95+
}, {
96+
id: 2,
97+
getBoundingClientRect: () => {
98+
return {left: 2};
99+
},
100+
}, {
101+
id: 3,
102+
getBoundingClientRect: () => {
103+
return {left: 12};
104+
},
105+
}];
106+
findStartExitId(children, wrapper).should.equal(2);
107+
});
108+
it('should wrapper left be counted', () => {
109+
const wrapper = {
110+
getBoundingClientRect: () => {
111+
return {left: 10};
112+
},
113+
};
85114
const children = [{
86115
id: 1,
87116
getBoundingClientRect: () => {
@@ -98,7 +127,7 @@ describe('engine/strape.js', () => {
98127
return {left: 12};
99128
},
100129
}];
101-
findStartExitId(children).should.equal(2);
130+
findStartExitId(children, wrapper).should.equal(3);
102131
});
103132
});
104133
});

0 commit comments

Comments
 (0)