Skip to content

Commit c61f63e

Browse files
authored
feat(components): autocomplete - add placement property
1 parent c27c610 commit c61f63e

File tree

7 files changed

+87
-5
lines changed

7 files changed

+87
-5
lines changed

src/components/ui/autocomplete/autocomplete.component.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
PopoverElement,
3131
} from '../popover/popover.component';
3232
import { InputFocusEvent } from '../support/typings';
33+
import { PopoverPlacement } from '../popover/type';
3334

3435
export interface AutocompleteOption {
3536
title: string;
@@ -40,6 +41,7 @@ export interface AutocompleteProps<O extends Option = Option> extends InputProps
4041
placeholderData?: O[];
4142
onSelect?: (option: O) => void;
4243
renderItem?: (info: ListRenderItemInfo<O>) => React.ReactElement;
44+
placement?: PopoverPlacement | string;
4345
}
4446

4547
export type AutocompleteElement<O extends Option = Option> = React.ReactElement<AutocompleteProps<O>>;
@@ -79,6 +81,12 @@ interface State {
7981
* @property {(info: ListRenderItemInfo<AutocompleteOption>) => ReactElement} renderItem - Takes an
8082
* item from data and renders it into the list. If not provided, ListItem is rendered.
8183
*
84+
* @property {string | PopoverPlacement} placement - Determines the actual placement of the popover.
85+
* Can be `left`, `top`, `right`, `bottom`, `left start`, `left end`, `top start`, `top end`, `right start`,
86+
* `right end`, `bottom start` or `bottom end`.
87+
* Default is `bottom`.
88+
* Tip: use one of predefined placements instead of strings, e.g `PopoverPlacements.TOP`
89+
*
8290
* @property {InputProps} ...InputProps - Any props applied to Input component.
8391
*
8492
* @overview-example AutocompleteSimpleUsage
@@ -93,6 +101,8 @@ interface State {
93101
*
94102
* @overview-example AutocompleteWithLabel
95103
*
104+
* @example AutocompleteHandleKeyboard
105+
*
96106
* @example AutocompleteAsync
97107
*/
98108
export class Autocomplete<O extends Option = Option> extends React.Component<AutocompleteProps<O>, State> {
@@ -206,6 +216,7 @@ export class Autocomplete<O extends Option = Option> extends React.Component<Aut
206216
<Popover
207217
ref={this.popoverRef}
208218
style={styles.popover}
219+
placement={this.props.placement}
209220
visible={this.state.optionsVisible}
210221
fullWidth={true}
211222
content={listElement}

src/components/ui/datepicker/datepicker.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export type DatepickerElement<D = Date> = React.ReactElement<DatepickerProps<D>>
8888
*
8989
* @property {() => ReactElement} renderFooter - Should return the footer.
9090
*
91-
* @property {string | PopoverPlacement} placement - Determines the actualPlacement of the popover.
91+
* @property {string | PopoverPlacement} placement - Determines the actual placement of the popover.
9292
* Can be `left`, `top`, `right`, `bottom`, `left start`, `left end`, `top start`, `top end`, `right start`,
9393
* `right end`, `bottom start` or `bottom end`.
9494
* Default is `bottom`.

src/components/ui/datepicker/rangeDatepicker.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export type RangeDatepickerElement<D = Date> = React.ReactElement<RangeDatepicke
8888
*
8989
* @property {() => ReactElement} renderFooter - Should return the footer.
9090
*
91-
* @property {string | PopoverPlacement} placement - Determines the actualPlacement of the popover.
91+
* @property {string | PopoverPlacement} placement - Determines the placement of the popover.
9292
* Can be `left`, `top`, `right`, `bottom`, `left start`, `left end`, `top start`, `top end`, `right start`,
9393
* `right end`, `bottom start` or `bottom end`.
9494
* Default is `bottom`.

src/components/ui/overflowMenu/overflowMenu.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export type OverflowMenuElement = React.ReactElement<OverflowMenuProps>;
5555
*
5656
* @property {(index: number, event: GestureResponderEvent) => void} onSelect - Fires when selected item is changed.
5757
*
58-
* @property {string | PopoverPlacement} placement - Determines the actualPlacement of the popover.
58+
* @property {string | PopoverPlacement} placement - Determines the placement of the popover.
5959
* Can be `left`, `top`, `right`, `bottom`, `left start`, `left end`, `top start`, `top end`, `right start`,
6060
* `right end`, `bottom start` or `bottom end`.
6161
* Default is `bottom`.

src/components/ui/popover/popover.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const POINT_OUTSCREEN: Point = new Point(-999, -999);
6363
*
6464
* @property {ReactElement} children - Determines the element "above" which popover will be shown.
6565
*
66-
* @property {string | PopoverPlacement} placement - Determines the actualPlacement of the popover.
66+
* @property {string | PopoverPlacement} placement - Determines the placement of the popover.
6767
* Can be `left`, `top`, `right`, `bottom`, `left start`, `left end`, `top start`, `top end`, `right start`,
6868
* `right end`, `bottom start` or `bottom end`.
6969
* Default is `bottom`.

src/components/ui/tooltip/tooltip.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export type TooltipElement = React.ReactElement<TooltipProps>;
6262
*
6363
* @property {ReactElement} children - Determines the element "above" which popover will be shown.
6464
*
65-
* @property {string | PopoverPlacement} placement - Determines the actualPlacement of the popover.
65+
* @property {string | PopoverPlacement} placement - Determines the placement of the popover.
6666
* Can be `left`, `top`, `right`, `bottom`, `left start`, `left end`, `top start`, `top end`, `right start`,
6767
* `right end`, `bottom start` or `bottom end`.
6868
* Default is `bottom`.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React from 'react';
2+
import { Keyboard, Platform, StyleSheet } from 'react-native';
3+
import { Autocomplete, Layout } from '@ui-kitten/components';
4+
5+
const DATA = [
6+
{ title: 'Star Wars' },
7+
{ title: 'Back to the Future' },
8+
{ title: 'The Matrix' },
9+
{ title: 'Inception' },
10+
{ title: 'Interstellar' },
11+
];
12+
13+
const showEvent = Platform.select({
14+
android: 'keyboardDidShow',
15+
default: 'keyboardWillShow',
16+
});
17+
18+
const hideEvent = Platform.select({
19+
android: 'keyboardDidHide',
20+
default: 'keyboardWillHide',
21+
});
22+
23+
export const AutocompleteHandleKeyboardShowcase = () => {
24+
25+
const [value, setValue] = React.useState(null);
26+
const [data, setData] = React.useState(DATA);
27+
const [placement, setPlacement] = React.useState('bottom');
28+
29+
React.useEffect(() => {
30+
const keyboardShowListener = Keyboard.addListener(showEvent, () => {
31+
setPlacement('top');
32+
});
33+
34+
const keyboardHideListener = Keyboard.addListener(hideEvent, () => {
35+
setPlacement('bottom');
36+
});
37+
38+
return () => {
39+
keyboardShowListener.remove();
40+
keyboardHideListener.remove();
41+
};
42+
});
43+
44+
const onSelect = ({ title }) => {
45+
setValue(title);
46+
};
47+
48+
const onChangeText = (query) => {
49+
setValue(query);
50+
setData(DATA.filter(item => item.title.toLowerCase().includes(query.toLowerCase())));
51+
};
52+
53+
return (
54+
<Layout style={styles.container}>
55+
<Autocomplete
56+
placeholder='Place your Text'
57+
value={value}
58+
data={data}
59+
placement={placement}
60+
onChangeText={onChangeText}
61+
onSelect={onSelect}
62+
/>
63+
</Layout>
64+
);
65+
};
66+
67+
const styles = StyleSheet.create({
68+
container: {
69+
minHeight: 228,
70+
},
71+
});

0 commit comments

Comments
 (0)