Skip to content

Commit

Permalink
fix: APP-2816 - Update InputSearch component to fix SSR (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgero-eth authored Jan 12, 2024
1 parent ca6cb7b commit f257797
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Update `Spinner` and `Button` components to handle responsive sizes
- Update `Icon` and `AvatarIcon` components to handle xl and 2xl responsive sizes

### Fixed

- Update `InputSearch` component to fix server-side rendering

## [1.0.6] - 2023-12-13

### Added
Expand Down
7 changes: 3 additions & 4 deletions src/components/input/inputSearch/inputSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export interface IInputSearchProps extends IInputComponentProps {
isLoading?: boolean;
}

// Needed to trigger a native onChange event on clear input click (see https://stackoverflow.com/a/46012210)
const nativeValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set;

export const InputSearch: React.FC<IInputSearchProps> = (props) => {
const { isLoading, ...otherProps } = props;
const { containerProps, inputProps } = useInputProps(otherProps);
Expand All @@ -40,7 +37,9 @@ export const InputSearch: React.FC<IInputSearchProps> = (props) => {
return;
}

nativeValueSetter?.call(inputRef.current, '');
// Needed to trigger a native onChange event on clear input click (see https://stackoverflow.com/a/46012210)
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set?.call(inputRef.current, '');

const event = new Event('input', { bubbles: true });
inputRef.current.dispatchEvent(event);

Expand Down

0 comments on commit f257797

Please sign in to comment.