Skip to content

Commit

Permalink
[FEAT] Use MenuItem (dropdown menu) to select year
Browse files Browse the repository at this point in the history
This should not be merged until mui/material-ui#3289 is fixed.

Opening the dropdown causes about 4000ms under a desktop, using Chrome.
This provides a awful UX to users because of the lag issue.
  • Loading branch information
Holi0317 committed Apr 17, 2016
1 parent 0e02d06 commit 8194acb
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions app/components/RangeSelector.jsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
import React from 'react';
import AutoComplete from 'material-ui/AutoComplete';
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';

const yearPrefix = '20'
const minYear = 10;
const maxYear = 99;
const dataSource = [];
const minYear = 2010;
const maxYear = 2099;
let yearItems = [];
for (let i = minYear; i <= maxYear; i++) {
dataSource.push(String(i));
}

/**
* This function strips the given number and return the last two digit of the number.
* WARNING: The return type is a string.
*
* @param year {Number} - Number for operation.
* @returns {String} - Last two digit of the number.
*/
function yearStrip(year) {
return String(year).slice(2);
}

function processProps(props) {
return {
searchText: yearStrip(props.value),
onUpdateInput(searchText) {
props.onChange(Number(yearPrefix + searchText));
}
}
yearItems.push(
<MenuItem key={i - minYear} primaryText={i} value={i} />
);
}

export default function RangeSelector(props) {
return (
<div>
<spam>從西曆 {yearPrefix}</spam>
<AutoComplete dataSource={dataSource} hintText="年份" {...processProps(props.start)} />
<spam> 年 正月初一 重複至 西曆 {yearPrefix}</spam>
<AutoComplete dataSource={dataSource} hintText="年份" {...processProps(props.end)} />
<spam>從西曆 </spam>
<SelectField {...props.start}>
{yearItems}
</SelectField>
<spam> 年 正月初一 重複至 西曆 </spam>
<SelectField {...props.end}>
{yearItems}
</SelectField>
<spam> 年 正月初一 的前一天</spam>
</div>
);
Expand Down

0 comments on commit 8194acb

Please sign in to comment.