Skip to content

Commit

Permalink
use custom time input until facebook/react#3659 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
siren committed Mar 3, 2017
1 parent e3c2589 commit 8c5990b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
30 changes: 30 additions & 0 deletions app/component/CustomInputTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { PropTypes } from 'react';
import { isMobile } from '../util/browser';

export default function CustomInputTime({ changeTime, time }) {
let timeInput = null;
return (
<input
type="time"
className={`time-selector ${!isMobile ? 'time-selector' : ''}`}
value={time}
onChange={changeTime}
ref={(input) => {
// use ref callback to bind change listener so that it works on android/firefox too
if (input !== null && timeInput === null) {
timeInput = input;
const listener = (a) => {
changeTime(a); a.target.blur(); a.target.removeEventListener('change', this);
};
input.addEventListener('change', listener);
}
}}
/>
);
}


CustomInputTime.propTypes = {
changeTime: PropTypes.func.isRequired,
time: PropTypes.string.isRequired,
};
15 changes: 7 additions & 8 deletions app/component/TimeSelectors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { PropTypes } from 'react';
import moment from 'moment';
import { intlShape } from 'react-intl';
import cx from 'classnames';
import { isMobile } from '../util/browser';

import Icon from './Icon';
import ComponentUsageExample from './ComponentUsageExample';
import supportsInputType from '../util/supportsInputType';
import TimeInput from './TimeInput';
import CustomInputTime from './CustomInputTime';

export default function TimeSelectors(
{ arriveBy, time, dates, setArriveBy, changeTime, changeDate }, { intl },
Expand Down Expand Up @@ -41,14 +42,12 @@ export default function TimeSelectors(
<Icon className="fake-select-arrow" img="icon-icon_arrow-dropdown" />
</div>
{supportsInputType('time') ?
<div className="select-wrapper">
<input
type="time"
className={cx('time-selector', { desktop: !navigator.userAgent.match(/Mobile/) })}
value={time.format('HH:mm')}
onChange={changeTime}
<div id="time" className="select-wrapper">
<CustomInputTime
time={time.format('HH:mm')}
changeTime={changeTime}
/>
{navigator.userAgent.match(/Mobile/) &&
{isMobile &&
<Icon className="fake-select-arrow" img="icon-icon_arrow-dropdown" key="caret" />
}
</div> :
Expand Down

0 comments on commit 8c5990b

Please sign in to comment.