Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Warn in dev for child validation rather than return null (#180)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler Grove <tyler.grove@vimeo.com>
  • Loading branch information
tylerthegrove and Tyler Grove authored Sep 28, 2022
1 parent e743dcc commit 6649e65
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/components/inputs/Checkbox/CheckboxSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ function CheckboxSetComponent({
checksSet(initialState);
}, [children, coupled, defaultChecked]);

if (!validate(children, 'checkbox') && DEV)
console.warn('Unable to validate children on CheckboxSet');
validate(children, 'checkbox');

const allChecked = checks.every((check) => check);
const someChecked = !allChecked && checks.some((check) => check);
Expand Down Expand Up @@ -128,7 +127,5 @@ function CheckboxSetComponent({
);
}

const DEV = process.env.NODE_ENV === 'development';

const toggle = (index) => (checked) =>
checked.map((val, i) => (index === i ? !val : val));
2 changes: 1 addition & 1 deletion src/components/inputs/Radio/RadioSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function RadioSetComponent({
initialCheckedIndex
);

if (!validate(children, 'radio')) return null;
validate(children, 'radio');

function onChange(event) {
if (event.target.checked) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/inputs/Shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { rgba, rem } from 'polished';
import { blue, white } from '../../color';
import { Statuses } from '../../themes';

const isDev = process?.env?.NODE_ENV === 'development';

export function inputColors({ theme, disabled = false, format }) {
if (!format || !theme.formats[format]) format = 'basic';

Expand Down Expand Up @@ -283,7 +285,7 @@ export function validate(
const Name = type.charAt(0).toUpperCase() + type.slice(1);
const valid = children.every(compareMetas(type));

if (!valid) {
if (!valid && isDev) {
console.warn(
`<${Name}Set /> children must be <${Name} />.`,
children
Expand Down

0 comments on commit 6649e65

Please sign in to comment.