Skip to content

Commit

Permalink
blur action prop to accept onBlur event
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-rajpal committed Nov 16, 2023
1 parent c09ef5b commit 64d8114
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/fuselage/src/components/AutoComplete/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
AllHTMLAttributes,
ComponentProps,
ElementType,
FocusEventHandler,
ReactElement,
} from 'react';
import React, { useEffect, useRef, useMemo, useState } from 'react';
Expand Down Expand Up @@ -42,7 +43,8 @@ type AutoCompleteProps = {
error?: boolean;
disabled?: boolean;
multiple?: boolean;
} & Omit<AllHTMLAttributes<HTMLInputElement>, 'onChange'>;
onBlurAction?: FocusEventHandler;
} & Omit<AllHTMLAttributes<HTMLInputElement>, 'onChange', 'onBlur'>;

const getSelected = (
value: string | string[],
Expand All @@ -69,6 +71,7 @@ export function AutoComplete({
error,
disabled,
multiple,
onBlurAction = () => {},
...props
}: AutoCompleteProps): ReactElement {
const ref = useRef();
Expand Down Expand Up @@ -121,6 +124,11 @@ export function AutoComplete({
const [cursor, handleKeyDown, , reset, [optionsAreVisible, hide, show]] =
useCursor(value, memoizedOptions, handleSelect);

const onBlur = useMutableCallback((event) => {
hide();
onBlurAction(event);
});

useEffect(reset, [filter]);

return (
Expand Down Expand Up @@ -148,7 +156,7 @@ export function AutoComplete({
onChange={useMutableCallback((e) =>
setFilter(e.currentTarget.value)
)}
onBlur={hide}
onBlur={onBlur}
onFocus={show}
onKeyDown={handleKeyDown}
placeholder={
Expand Down

0 comments on commit 64d8114

Please sign in to comment.