Skip to content

Commit

Permalink
feat: don't render both checked and defaultChecked when passing argum…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
orrgottlieb committed Dec 30, 2020
1 parent 80ef273 commit b11ee70
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monday-ui-react-core",
"version": "0.0.50",
"version": "0.0.51",
"description": "Official monday.com UI resources for application development in React.js",
"main": "dist/main.js",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions src/components/RadioButton/RadioButton.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, forwardRef, useCallback } from "react";
import React, { useRef, forwardRef, useCallback, useMemo } from "react";
import PropTypes from "prop-types";
import cx from "classnames";
import useMergeRefs from "../../hooks/useMergeRefs";
Expand All @@ -19,6 +19,13 @@ const RadioButton = forwardRef(
}
}, [onSelect, inputRef, disabled]);

const checkedProps = useMemo(() => {
if (checked !== undefined) {
return { checked };
}
return { defaultChecked };
}, [checked, defaultChecked]);

return (
<label className={cx(baseClassName, componentClassName, { disabled })}>
<span className={`${baseClassName}__radio-input-container`}>
Expand All @@ -27,9 +34,8 @@ const RadioButton = forwardRef(
type="radio"
value={value}
name={name}
checked={checked}
disabled={disabled}
defaultChecked={defaultChecked}
{...checkedProps}
onChange={onSelect}
ref={mergedRef}
/>
Expand Down
12 changes: 11 additions & 1 deletion src/components/RadioButton/__stories__/radioButton.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const States = () => {
disabled={true}
/>
</RadioButtonStoryLine>
<RadioButtonStoryLine title="Selected">
<RadioButtonStoryLine title="Default Checked">
<RadioButton
value="1"
text="Option"
Expand All @@ -49,6 +49,16 @@ export const States = () => {
componentClassName="monday-style-radio-button-selected"
/>
</RadioButtonStoryLine>
<RadioButtonStoryLine title="Checked">
<RadioButton
value="1"
text="Option"
name="selectedRadio"
checked={true}
disabled={true}
componentClassName="monday-style-radio-button-selected"
/>
</RadioButtonStoryLine>
<RadioButtonStoryLine title="Selected hover">
<RadioButton
value="1"
Expand Down

0 comments on commit b11ee70

Please sign in to comment.