diff --git a/src/Explorer/Controls/InputTypeahead/InputTypeahead.less b/src/Explorer/Controls/InputTypeahead/InputTypeahead.less
index e56bfaa51..1d68e3b7e 100644
--- a/src/Explorer/Controls/InputTypeahead/InputTypeahead.less
+++ b/src/Explorer/Controls/InputTypeahead/InputTypeahead.less
@@ -5,6 +5,9 @@
display: inline-block;
width: 100%;
+ .input-type-head-text-field {
+ width: 100%;
+ }
textarea {
width: 100%;
line-height: 1;
@@ -21,4 +24,11 @@
}
}
}
-
+.input-typeahead-chocies-container {
+ border: 1px solid lightgrey;
+ padding: 5px 10px 5px 10px;
+ cursor: pointer;
+ .choice-caption{
+ font-size: 14px;
+ }
+}
\ No newline at end of file
diff --git a/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx b/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx
index 69f01a745..2e9a2d104 100644
--- a/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx
+++ b/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx
@@ -6,14 +6,13 @@
* typeaheadOverrideOptions: { dynamic:false }
*
*/
-import "jquery-typeahead";
+import { getTheme, IconButton, IIconProps, List, Stack, TextField } from "@fluentui/react";
import * as React from "react";
-import { KeyCodes } from "../../../Common/Constants";
import "./InputTypeahead.less";
export interface Item {
caption: string;
- value: any;
+ value: string;
}
/**
@@ -75,170 +74,125 @@ export interface InputTypeaheadComponentProps {
useTextarea?: boolean;
}
-interface OnClickItem {
- matchedKey: string;
- value: any;
- caption: string;
- group: string;
+interface InputTypeaheadComponentState {
+ isSuggestionVisible: boolean;
+ selectedChoice: Item;
+ filteredChoices: Item[];
}
-interface Cache {
- inputValue: string;
- selection: Item;
-}
-
-interface InputTypeaheadComponentState {}
-
export class InputTypeaheadComponent extends React.Component<
InputTypeaheadComponentProps,
InputTypeaheadComponentState
> {
- private inputElt: HTMLElement;
- private containerElt: HTMLElement;
-
- private cache: Cache;
- private inputValue: string;
- private selection: Item;
-
- public constructor(props: InputTypeaheadComponentProps) {
+ constructor(props: InputTypeaheadComponentProps) {
super(props);
- this.cache = {
- inputValue: null,
- selection: null,
+ this.state = {
+ isSuggestionVisible: false,
+ filteredChoices: [],
+ selectedChoice: {
+ caption: "",
+ value: "",
+ },
};
}
- /**
- * Props have changed
- * @param prevProps
- * @param prevState
- * @param snapshot
- */
- public componentDidUpdate(
- prevProps: InputTypeaheadComponentProps,
- prevState: InputTypeaheadComponentState,
- snapshot: any
- ): void {
- if (prevProps.defaultValue !== this.props.defaultValue) {
- $(this.inputElt).val(this.props.defaultValue);
- this.initializeTypeahead();
- }
- }
-
- /**
- * Executed once react is done building the DOM for this component
- */
- public componentDidMount(): void {
- this.initializeTypeahead();
- }
-
- public render(): JSX.Element {
+ private onRenderCell = (item: Item): JSX.Element => {
return (
-
- ) => this.onKeyDown(event)}
- >
-
(this.containerElt = input)}>
-
-
- {this.props.useTextarea ? (
-
- {this.props.showSearchButton && (
-
-
-
- )}
-
-
-
-
+
this.onChoiceClick(item)}>
+
{item.caption}
+
{item.value}
+
);
- }
+ };
- private onKeyDown(event: React.KeyboardEvent) {
- if (event.keyCode === KeyCodes.Enter) {
+ private onChoiceClick = (item: Item): void => {
+ this.props.onNewValue(item.caption);
+ this.setState({ isSuggestionVisible: false, selectedChoice: item });
+ };
+
+ private handleChange = (value: string): void => {
+ if (!value) {
+ this.setState({ isSuggestionVisible: true });
+ }
+ this.props.onNewValue(value);
+ const filteredChoices = this.filterChoiceByValue(this.props.choices, value);
+ this.setState({ filteredChoices });
+ };
+
+ private onSubmit = (event: React.KeyboardEvent): void => {
+ if (event.key === "Enter") {
if (this.props.submitFct) {
event.preventDefault();
event.stopPropagation();
- this.props.submitFct(this.cache.inputValue, this.cache.selection);
- $(this.containerElt).children(".typeahead__result").hide();
+ this.props.submitFct(this.props.defaultValue, this.state.selectedChoice);
+ this.setState({ isSuggestionVisible: false });
}
}
- }
+ };
- /**
- * Must execute once ko is rendered, so that it can find the input element by id
- */
- private initializeTypeahead(): void {
- const props = this.props;
- let cache = this.cache;
- let options: any = {
- input: this.inputElt,
- order: "asc",
- minLength: 0,
- searchOnFocus: true,
- source: {
- display: "caption",
- data: () => {
- return props.choices;
- },
- },
- callback: {
- onClick: (node: any, a: any, item: OnClickItem, event: any) => {
- cache.selection = item;
+ private filterChoiceByValue = (choices: Item[], searchKeyword: string): Item[] => {
+ return choices.filter((choice) =>
+ // @ts-ignore
+ Object.keys(choice).some((key) => choice[key].toLowerCase().includes(searchKeyword.toLowerCase()))
+ );
+ };
- if (props.onSelected) {
- props.onSelected(item);
- }
- },
- onResult(node: any, query: any, result: any, resultCount: any, resultCountPerGroup: any) {
- cache.inputValue = query;
- if (props.onNewValue) {
- props.onNewValue(query);
- }
- },
+ public render(): JSX.Element {
+ const { defaultValue, useTextarea, placeholder, onNewValue } = this.props;
+ const { isSuggestionVisible, selectedChoice, filteredChoices } = this.state;
+ const theme = getTheme();
+
+ const iconButtonStyles = {
+ root: {
+ color: theme.palette.neutralPrimary,
+ marginLeft: "10px !important",
+ marginTop: "0px",
+ marginRight: "2px",
+ width: "42px",
},
- template: (query: string, item: any) => {
- // Don't display id if caption *IS* the id
- return item.caption === item.value
- ? "{{caption}}"
- : "{{caption}}
{{value}}
";
+ rootHovered: {
+ color: theme.palette.neutralDark,
},
- dynamic: true,
};
+ const cancelIcon: IIconProps = { iconName: "cancel" };
+ const searchIcon: IIconProps = { iconName: "Search" };
- // Override options
- if (props.typeaheadOverrideOptions) {
- for (const p in props.typeaheadOverrideOptions) {
- options[p] = props.typeaheadOverrideOptions[p];
- }
- }
-
- if (props.hasOwnProperty("showCancelButton")) {
- options.cancelButton = props.showCancelButton;
- }
-
- $(this.inputElt).typeahead(options);
+ return (
+
+
+ this.setState({ isSuggestionVisible: true })}
+ onChange={(_event, newValue?: string) => this.handleChange(newValue)}
+ />
+ {this.props.showCancelButton && (
+ onNewValue("")}
+ />
+ )}
+ {this.props.showSearchButton && (
+ this.props.submitFct(defaultValue, selectedChoice)}
+ />
+ )}
+
+ {filteredChoices.length && isSuggestionVisible ? (
+
+ ) : undefined}
+
+ );
}
}
diff --git a/src/Explorer/Controls/InputTypeahead/__snapshots__/InputTypeaheadComponent.test.tsx.snap b/src/Explorer/Controls/InputTypeahead/__snapshots__/InputTypeaheadComponent.test.tsx.snap
index 788652d84..ca534c822 100644
--- a/src/Explorer/Controls/InputTypeahead/__snapshots__/InputTypeaheadComponent.test.tsx.snap
+++ b/src/Explorer/Controls/InputTypeahead/__snapshots__/InputTypeaheadComponent.test.tsx.snap
@@ -1,61 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`inputTypeahead renders 1`] = `
-
-
-
+
+
+
`;
exports[`inputTypeahead renders 1`] = `
-
-
-
+
+
+
`;