Skip to content

Commit da47f21

Browse files
imaspennecolas
authored andcommitted
[add] Support showSoftInputOnFocus on TextInput
Close #2659 Fix #2548
1 parent 2106944 commit da47f21

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

packages/react-native-web-docs/src/pages/docs/components/text-input.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ permalink: /docs/text-input/index.html
55
eleventyNavigation:
66
key: TextInput
77
parent: Components
8-
label: "Change"
8+
label: 'Change'
99
---
1010

1111
{% import "fragments/macros.html" as macro with context %}
@@ -168,6 +168,10 @@ If `true`, all text will automatically be selected on focus.
168168
Equivalent to [HTMLElement.spellcheck](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck)
169169
{% endcall %}
170170

171+
{% call macro.prop('showSoftInputOnFocus', '?boolean = true') %}
172+
If `false`, will set [HTMLElement.virtualkeyboardpolicy](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/virtualkeyboardpolicy) to `manual`.
173+
{% endcall %}
174+
171175
{% call macro.prop('style', '?Style') %}
172176
Set the styles of the view. `TextInput` supports typographic styles in addition to those of `View`.
173177
{% endcall %}

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

+20
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,26 @@ describe('components/TextInput', () => {
740740
expect(input.value).toEqual(value);
741741
});
742742

743+
describe('prop "showSoftInputOnFocus"', () => {
744+
test('default value', () => {
745+
const { container } = render(<TextInput />);
746+
const input = findInput(container);
747+
expect(input.getAttribute('virtualkeyboardpolicy')).toEqual('auto');
748+
});
749+
750+
test('true value', () => {
751+
const { container } = render(<TextInput showSoftInputOnFocus={true} />);
752+
const input = findInput(container);
753+
expect(input.getAttribute('virtualkeyboardpolicy')).toEqual('auto');
754+
});
755+
756+
test('false value', () => {
757+
const { container } = render(<TextInput showSoftInputOnFocus={false} />);
758+
const input = findInput(container);
759+
expect(input.getAttribute('virtualkeyboardpolicy')).toEqual('manual');
760+
});
761+
});
762+
743763
describe('imperative methods', () => {
744764
test('node.clear()', () => {
745765
const ref = React.createRef();

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

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const TextInput: React.AbstractComponent<
140140
secureTextEntry = false,
141141
selection,
142142
selectTextOnFocus,
143+
showSoftInputOnFocus,
143144
spellCheck
144145
} = props;
145146

@@ -419,6 +420,8 @@ const TextInput: React.AbstractComponent<
419420
caretHidden && styles.caretHidden
420421
];
421422
supportedProps.type = multiline ? undefined : type;
423+
supportedProps.virtualkeyboardpolicy =
424+
showSoftInputOnFocus === false ? 'manual' : 'auto';
422425

423426
const platformMethodsRef = usePlatformMethods(supportedProps);
424427

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

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type TextInputProps = {
6969
end?: number
7070
|},
7171
selectionColor?: ?ColorValue,
72+
showSoftInputOnFocus?: ?boolean,
7273
spellCheck?: ?boolean,
7374
style?: ?GenericStyleProp<TextInputStyle>,
7475
value?: ?string,

0 commit comments

Comments
 (0)