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

Prevent transition props from being forwarded to <input> element in DummyInput component #5057

Merged
merged 7 commits into from Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-knives-punch.md
@@ -0,0 +1,5 @@
---
'react-select': patch
---

Prevent transition props from being forwarded to `<input>` element in `DummyInput` component
13 changes: 12 additions & 1 deletion packages/react-select/src/internal/DummyInput.tsx
@@ -1,17 +1,28 @@
/** @jsx jsx */
import { Ref } from 'react';
import { jsx } from '@emotion/react';
import { removeProps } from '../utils';

export default function DummyInput({
innerRef,
...props
}: JSX.IntrinsicElements['input'] & {
readonly innerRef: Ref<HTMLInputElement>;
}) {
// Remove animation props not meant for HTML elements
const filteredProps = removeProps(
props,
'onExited',
'in',
'enter',
'exit',
'appear'
);

return (
<input
ref={innerRef}
{...props}
{...filteredProps}
css={{
label: 'dummyInput',
// get rid of any default styles
Expand Down
14 changes: 14 additions & 0 deletions packages/react-select/src/utils.ts
Expand Up @@ -367,3 +367,17 @@ export function multiValueAsValue<Option, IsMulti extends boolean>(
): OnChangeValue<Option, IsMulti> {
return multiValue as OnChangeValue<Option, IsMulti>;
}

export const removeProps = <Props extends object, K extends string[]>(
propsObj: Props,
...properties: K
): Omit<Props, K[number]> => {
let propsMap = Object.entries(propsObj).filter(
([key]) => !properties.includes(key)
);

return propsMap.reduce((newProps: { [key: string]: any }, [key, val]) => {
newProps[key] = val;
return newProps;
}, {}) as Omit<Props, K[number]>;
};