Skip to content

Commit

Permalink
Alternative way to remove props.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rall3n committed Mar 3, 2022
1 parent c03082a commit 92f07dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/react-select/src/internal/DummyInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx jsx */
import { Ref } from 'react';
import { jsx } from '@emotion/react';
import { TransitionProps } from 'react-transition-group/Transition';
import { removeProps } from '../utils';

export default function DummyInput({
innerRef,
Expand All @@ -10,12 +10,12 @@ export default function DummyInput({
readonly innerRef: Ref<HTMLInputElement>;
}) {
// Remove animation props not meant for HTML elements
const { onExited, in: _, enter, exit, appear, ...noAnimProps } = props as (JSX.IntrinsicElements['input'] & Partial<TransitionProps>);
const filteredProps = removeProps(props, 'onExited', 'in', 'enter', 'exit', 'appear');

return (
<input
ref={innerRef}
{...noAnimProps}
{...filteredProps}
css={{
label: 'dummyInput',
// get rid of any default styles
Expand Down
12 changes: 12 additions & 0 deletions packages/react-select/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,15 @@ 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]>;
};

0 comments on commit 92f07dc

Please sign in to comment.