-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@mantine/styles] Fix components props with undefined value from coll…
…istions with default props (#985)
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/mantine-styles/src/theme/utils/filter-props/filter-props.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { filterProps } from './filter-props'; | ||
|
||
describe('@mantine/styles filterProps', () => { | ||
it('filters out props with undefined value', () => { | ||
expect( | ||
filterProps({ | ||
a: undefined, | ||
b: null, | ||
c: 0, | ||
d: '', | ||
e: {}, | ||
f: [], | ||
}) | ||
).toStrictEqual({ | ||
b: null, | ||
c: 0, | ||
d: '', | ||
e: {}, | ||
f: [], | ||
}); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
src/mantine-styles/src/theme/utils/filter-props/filter-props.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function filterProps<T extends Record<string, any>>(props: T) { | ||
return Object.keys(props).reduce<T>((acc, key: keyof T) => { | ||
if (props[key] !== undefined) { | ||
acc[key] = props[key]; | ||
} | ||
return acc; | ||
}, {} as T); | ||
} |