From e049695bed5a41485d88514431275b77a750b741 Mon Sep 17 00:00:00 2001 From: jordankoschei-okta Date: Tue, 11 Jul 2023 15:56:57 -0400 Subject: [PATCH 1/8] feat: hide native clear button --- .../odyssey-react-mui/src/theme/components.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/odyssey-react-mui/src/theme/components.tsx b/packages/odyssey-react-mui/src/theme/components.tsx index 8f10e854b1..d3438dbf3e 100644 --- a/packages/odyssey-react-mui/src/theme/components.tsx +++ b/packages/odyssey-react-mui/src/theme/components.tsx @@ -1469,6 +1469,21 @@ export const components = ( opacity: "1 !important", }, }, + + [`&::-webkit-search-cancel-button`]: { + display: "none", + "-webkit-appearance": "none", + "-moz-appearance": "none", + }, + + [`&::-moz-search-cancel-button`]: { + display: "none", + "-moz-appearance": "none", + }, + + [`&::-ms-clear`]: { + display: "none", + }, }, }, }, From 456e368a8c63be4b1e47943f5702575c54827026 Mon Sep 17 00:00:00 2001 From: jordankoschei-okta Date: Tue, 11 Jul 2023 22:28:17 -0400 Subject: [PATCH 2/8] feat: add custom button for search clear --- .../odyssey-react-mui/src/SearchField.tsx | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/packages/odyssey-react-mui/src/SearchField.tsx b/packages/odyssey-react-mui/src/SearchField.tsx index 4e849dd24b..4bf85251f0 100644 --- a/packages/odyssey-react-mui/src/SearchField.tsx +++ b/packages/odyssey-react-mui/src/SearchField.tsx @@ -10,6 +10,7 @@ * See the License for the specific language governing permissions and limitations under the License. */ +import { useState, useEffect } from "react"; import { InputAdornment, InputBase } from "@mui/material"; import { ChangeEventHandler, @@ -20,8 +21,9 @@ import { useCallback, } from "react"; -import { SearchIcon } from "./iconDictionary"; +import { CloseCircleFilledIcon, SearchIcon } from "./iconDictionary"; import { Field } from "./Field"; +import { Button } from "./Button"; export type SearchFieldProps = { /** @@ -50,6 +52,10 @@ export type SearchFieldProps = { * Callback fired when the `input` element loses focus. */ onBlur?: FocusEventHandler; + /** + * Callback fired when the clear button is pressed. + */ + onClear?: () => void; /** * Callback fired when the value is changed. */ @@ -76,14 +82,36 @@ const SearchField = forwardRef( id: idOverride, isDisabled = false, label, - onChange, + onChange: onChangeProp, onFocus, onBlur, + onClear: onClearProp, placeholder, - value, + value: controlledValue, }, ref ) => { + const [uncontrolledValue, setUncontrolledValue] = useState(""); + + const onChange = useCallback( + (e) => { + setUncontrolledValue(e.target.value); + if (onChangeProp) onChangeProp(e); + }, + [onChangeProp] + ); + + const onClear = useCallback(() => { + setUncontrolledValue(""); + if (onClearProp) onClearProp(); + }, [onClearProp]); + + useEffect(() => { + if (controlledValue !== undefined) { + setUncontrolledValue(controlledValue); + } + }, [controlledValue]); + const renderFieldComponent = useCallback( ({ ariaDescribedBy, id }) => ( ( autoComplete={autoCompleteType} /* eslint-disable-next-line jsx-a11y/no-autofocus */ autoFocus={hasInitialFocus} + endAdornment={ + uncontrolledValue.length > 0 && ( + +