Skip to content

Commit fc033a3

Browse files
committed
[add] TextInput disabled prop
Add support for disabling TextInput elements Fix #1036
1 parent 8fa9fc5 commit fc033a3

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

packages/docs/src/components/TextInput/TextInput.stories.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ofProps.propTypes = {
1111
blurOnSubmit: PropTypes.bool,
1212
clearTextOnFocus: PropTypes.bool,
1313
defaultValue: PropTypes.string,
14+
disabled: PropTypes.bool,
1415
editable: PropTypes.bool,
1516
keyboardType: PropTypes.string,
1617
maxLength: PropTypes.number,
@@ -52,6 +53,7 @@ export { default as autoCapitalize } from './examples/AutoCapitalize';
5253
export { default as blurOnSubmit } from './examples/BlurOnSubmit';
5354
export { default as clearButtonMode } from './examples/ClearButtonMode';
5455
export { default as clearTextOnFocus } from './examples/ClearTextOnFocus';
56+
export { default as disabled } from './examples/Disabled';
5557
export { default as editable } from './examples/Editable';
5658
export { default as keyboardType } from './examples/KeyboardType';
5759
export { default as maxLength } from './examples/MaxLength';

packages/docs/src/components/TextInput/TextInput.stories.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ into the field.
5656
</Story>
5757
</Preview>
5858

59-
### clearTextOnFocus: ?boolean = false
59+
### clearTextOnFocus
6060

6161
If `true`, clears the text field automatically when focused.
6262

@@ -72,6 +72,16 @@ Provides an initial value that will change when the user starts typing. Useful
7272
for simple use-cases where you don't want to deal with listening to events and
7373
updating the value prop to keep the controlled state in sync.
7474

75+
### disabled
76+
77+
If `true`, the input is disabled. (Web-only)
78+
79+
<Preview withSource='none'>
80+
<Story name="disabled">
81+
<Stories.disabled />
82+
</Story>
83+
</Preview>
84+
7585
### editable
7686

7787
If `false`, text is not editable (i.e., read-only).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { styles } from '../helpers';
3+
import { TextInput, View } from 'react-native';
4+
5+
export default function Disabled() {
6+
return (
7+
<View>
8+
<TextInput defaultValue="disabled text input" disabled={true} style={styles.textinput} />
9+
<TextInput
10+
defaultValue="disabled multiline text input"
11+
disabled={true}
12+
multiline={true}
13+
style={styles.multiline}
14+
/>
15+
</View>
16+
);
17+
}

packages/react-native-web/src/exports/TextInput/__tests__/index-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ describe('components/TextInput', () => {
7070
expect(input.prop('defaultValue')).toEqual(defaultValue);
7171
});
7272

73+
describe('prop "disabled"', () => {
74+
test('value "false"', () => {
75+
const input = findNativeInput(shallow(<TextInput />));
76+
expect(input.prop('disabled')).toEqual(undefined);
77+
});
78+
79+
test('value "true"', () => {
80+
const input = findNativeInput(shallow(<TextInput disabled={true} />));
81+
expect(input.prop('disabled')).toEqual(true);
82+
});
83+
});
84+
7385
describe('prop "editable"', () => {
7486
test('value "true"', () => {
7587
const input = findNativeInput(shallow(<TextInput />));

packages/react-native-web/src/exports/TextInput/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class TextInput extends React.Component<TextInputProps> {
100100
autoCorrect = true,
101101
autoFocus,
102102
defaultValue,
103+
disabled,
103104
editable = true,
104105
keyboardType = 'default',
105106
maxLength,
@@ -151,6 +152,7 @@ class TextInput extends React.Component<TextInputProps> {
151152
classList: [classes.textinput],
152153
defaultValue,
153154
dir: 'auto',
155+
disabled,
154156
enterkeyhint: returnKeyType,
155157
maxLength,
156158
onBlur: normalizeEventHandler(this._handleBlur),

packages/react-native-web/src/exports/TextInput/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type TextInputProps = {
2727
blurOnSubmit?: boolean,
2828
clearTextOnFocus?: boolean,
2929
defaultValue?: string,
30+
disabled?: boolean,
3031
editable?: boolean,
3132
inputAccessoryViewID?: string,
3233
keyboardType?:

0 commit comments

Comments
 (0)