Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added typescript types to fluid search and its skeleton state #17383

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ import classnames from 'classnames';
import { usePrefix } from '../../internal/usePrefix';
import { FormContext } from '../FluidForm/FormContext';

function FluidSearchSkeleton({ className, ...other }) {
const prefix = usePrefix();
export interface FluidSearchSkeletonProps {
/**
* Specify an optional className to be applied to the outer FluidForm wrapper
*/
className?: string;
}

const FluidSearchSkeleton: React.FC<FluidSearchSkeletonProps> = ({
className,
...other
}) => {
const prefix = usePrefix();
return (
<FormContext.Provider value={{ isFluid: true }}>
<div
Expand All @@ -27,7 +36,7 @@ function FluidSearchSkeleton({ className, ...other }) {
</div>
</FormContext.Provider>
);
}
};

FluidSearchSkeleton.propTypes = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,72 @@ import Search from '../Search';
import { usePrefix } from '../../internal/usePrefix';
import { FormContext } from '../FluidForm/FormContext';

const FluidSearch = React.forwardRef(function FluidSearch(
{ className, ...other },
ref
) {
export interface FluidSearchProps {
/**
* Specify an optional value for the `autocomplete` property on the underlying
* `<input>`, defaults to "off"
*/
autoComplete?: string;
/**
* Specify an optional className to be applied to the container node
*/
className?: string;
/**
* Specify a label to be read by screen readers on the "close" button
*/
closeButtonLabelText?: string;
/**
* Optionally provide the default value of the `<input>`
*/
defaultValue?: string | number;
/**
* Specify whether the `<input>` should be disabled
*/
disabled?: boolean;
/**
* Specify a custom `id` for the input
*/
id?: string;
/**
* Provide the label text for the Search icon
*/
labelText: React.ReactNode;
/**
* Optional callback called when the search value changes.
*/
onChange?(e: { target: HTMLInputElement; type: 'change' }): void;
/**
* Optional callback called when the search value is cleared.
*/
onClear?: () => void;
/**
* Provide a handler that is invoked on the key down event for the input
*/
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
/**
* Provide an optional placeholder text for the Search.
* Note: if the label and placeholder differ,
* VoiceOver on Mac will read both
*/
placeholder?: string;
/**
* Specify the role for the underlying `<input>`, defaults to `searchbox`
*/
role?: string;
/**
* Optional prop to specify the type of the `<input>`
*/
type?: string;
/**
* Specify the value of the `<input>`
*/
value?: string | number;
}

const FluidSearch: React.FC<FluidSearchProps> = React.forwardRef<
HTMLInputElement,
FluidSearchProps
>(function FluidSearch({ className, ...other }, ref) {
const prefix = usePrefix();
const classNames = classnames(`${prefix}--search--fluid`, className);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import { FluidSearchProps } from './FluidSearch';
import { FluidSearchSkeletonProps } from './FluidSearch.Skeleton';
export { default, default as FluidSearch } from './FluidSearch';

export { type FluidSearchProps, type FluidSearchSkeletonProps };
export { default as FluidSearchSkeleton } from './FluidSearch.Skeleton';
Loading