Skip to content

Commit 78ce5bc

Browse files
author
Viktoriya Savkina
committed
issue 560: updates DateInput component's readOnly prop to be configurable by consumer implementation
1 parent 8678153 commit 78ce5bc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/components/DateInput.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const defaultProps = {
3737
focused: false,
3838
disabled: false,
3939
required: false,
40-
readOnly: false,
40+
readOnly: null,
4141
showCaret: false,
4242

4343
onChange() {},
@@ -172,7 +172,7 @@ export default class DateInput extends React.Component {
172172
placeholder={placeholder}
173173
autoComplete="off"
174174
disabled={disabled}
175-
readOnly={readOnly || isTouch}
175+
readOnly={typeof readOnly === 'boolean' ? readOnly : isTouch}
176176
required={required}
177177
aria-describedby={screenReaderMessage && screenReaderMessageId}
178178
/>

test/components/DateInput_spec.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,18 @@ describe('DateInput', () => {
273273
expect(wrapper.state()).to.contain.keys({ isTouchDevice: false });
274274
});
275275

276-
it('sets readOnly when a touch device and props.readOnly === true', () => {
277-
const wrapper = shallow(<DateInput id="date" readOnly />);
276+
it('sets readOnly to true when no value was provided on a touch device', () => {
277+
const wrapper = shallow(<DateInput id="date" />);
278278
wrapper.setState({ isTouchDevice: true });
279279
wrapper.update();
280280
expect(!!wrapper.find('input').prop('readOnly')).to.equal(true);
281281
});
282282

283-
it('sets readOnly when a touch device and props.readOnly === false', () => {
283+
it('sets readOnly to provided value on a touch device', () => {
284284
const wrapper = shallow(<DateInput id="date" readOnly={false} />);
285285
wrapper.setState({ isTouchDevice: true });
286286
wrapper.update();
287-
expect(!!wrapper.find('input').prop('readOnly')).to.equal(true);
287+
expect(!!wrapper.find('input').prop('readOnly')).to.equal(false);
288288
});
289289

290290
describe('focus/isFocused', () => {

0 commit comments

Comments
 (0)