Skip to content

Commit

Permalink
fix(ScrollSelect): can not vertail align the selected item when count…
Browse files Browse the repository at this point in the history
… is even, close #211
  • Loading branch information
Javey committed Feb 15, 2019
1 parent d31deb4 commit 1cb67ef
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/scrollSelect/demos/infinite.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ScrollSelect from 'kpc/components/scrollSelect';
<ScrollSelect
data={{ self.generateData }}
v-model="value"
count={{ 10 }}
/>
```

Expand Down
5 changes: 4 additions & 1 deletion components/scrollSelect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ export default class ScrollSelect extends Intact {
}

_mount() {
const count = this.get('count');
const height = this.element.offsetHeight;
const itemHeight = this.refs.item.offsetHeight;
const totalHeight = this.refs.wrapper.offsetHeight;
this._deltaY = -Math.floor((totalHeight - height) / 2);
// for even count, #211
this._deltaY = -(Math.floor(count / 2) * itemHeight - (height - itemHeight) / 2);
this.set({
_translate: this._deltaY
});
Expand Down
2 changes: 1 addition & 1 deletion pages/scrollSelect/index.vdt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ import ScrollSelect from 'components/scrollSelect';

<ScrollSelect data={{ (value) => {
return Array.apply(null, {length: 10}).map((v, i) => i + value - 5);
} }} value={{ 2018 }} />
} }} value={{ 2018 }} count={{ 19 }}/>
</div>
4 changes: 2 additions & 2 deletions scripts/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ module.exports = function(isDev = true) {
path.resolve(__dirname, `../site/dist`);

const doc = new KDoc(
// './@(docs|components)/**/*.md',
'./@(docs|components)/layout/**/*.md',
'./@(docs|components)/**/*.md',
// './@(docs|components)/layout/**/*.md',
root
);

Expand Down

0 comments on commit 1cb67ef

Please sign in to comment.