diff --git a/packages/form/src/react/__specs__/__snapshots__/storyshots.spec.js.snap b/packages/form/src/react/__specs__/__snapshots__/storyshots.spec.js.snap
index 1fa794a207..879b1ee9f5 100644
--- a/packages/form/src/react/__specs__/__snapshots__/storyshots.spec.js.snap
+++ b/packages/form/src/react/__specs__/__snapshots__/storyshots.spec.js.snap
@@ -906,6 +906,8 @@ exports[`Storyshots Sample Form sample 1`] = `
>
+
+
diff --git a/packages/radio/src/css/index.js b/packages/radio/src/css/index.js
index 3975a04c79..eff413d599 100644
--- a/packages/radio/src/css/index.js
+++ b/packages/radio/src/css/index.js
@@ -54,8 +54,7 @@ export default {
'.psds-radio-button__circle-outer': {
width: '16px',
- marginRight: layout.spacingSmall,
- pointerEvents: 'none'
+ marginRight: layout.spacingSmall
},
'.psds-radio-button__circle': {
@@ -88,12 +87,7 @@ export default {
},
'.psds-radio-button__input': {
- opacity: 0,
- width: 0,
- height: 0,
- '&:focus': {
- outline: 'none'
- }
+ display: 'none'
},
'.psds-radio-button__label': {
diff --git a/packages/radio/src/react/__specs__/__snapshots__/storyshots.spec.js.snap b/packages/radio/src/react/__specs__/__snapshots__/storyshots.spec.js.snap
index ff385c2d7f..21dc2af67f 100644
--- a/packages/radio/src/react/__specs__/__snapshots__/storyshots.spec.js.snap
+++ b/packages/radio/src/react/__specs__/__snapshots__/storyshots.spec.js.snap
@@ -1,149 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Storyshots Radio controlled 1`] = `
-
-
-
- Selected:
- red
-
-
-
-
-
-
-`;
-
exports[`Storyshots Radio default 1`] = `
+
@@ -227,11 +90,15 @@ exports[`Storyshots Radio default 1`] = `
Green
+
+
@@ -276,7 +143,10 @@ exports[`Storyshots Radio disabled & error 1`] = `
>
+
+
+
+
@@ -402,7 +280,10 @@ exports[`Storyshots Radio disabled 1`] = `
>
+
+
+
+
@@ -528,7 +417,10 @@ exports[`Storyshots Radio error 1`] = `
>
+
+
+
+
@@ -654,7 +554,10 @@ exports[`Storyshots Radio labels 1`] = `
>
+
+
+
+
@@ -790,7 +701,10 @@ exports[`Storyshots Radio one selected 1`] = `
>
+
+
+
+
@@ -905,3 +827,153 @@ exports[`Storyshots Radio one selected 1`] = `
`;
+
+exports[`Storyshots Radio state demo 1`] = `
+
+
+
+ Selected:
+ red
+
+
+
+
+`;
diff --git a/packages/radio/src/react/__specs__/index.spec.js b/packages/radio/src/react/__specs__/index.spec.js
index d7329efdb8..348f0d2d2d 100644
--- a/packages/radio/src/react/__specs__/index.spec.js
+++ b/packages/radio/src/react/__specs__/index.spec.js
@@ -9,7 +9,7 @@ describe('Radio', () => {
const button = React.createRef()
render(
-
+
@@ -19,16 +19,16 @@ describe('Radio', () => {
expect(group.current).not.toBeNull()
expect(button.current).not.toBeNull()
})
- it('controlled: fires event once', () => {
+ it('fires event once', () => {
const spy = jest.fn()
const { container } = render(
-
+
)
- const radio = container.querySelector('input')
+ const radio = container.querySelector('label')
fireEvent.click(radio)
expect(spy).toHaveBeenCalledTimes(1)
})
diff --git a/packages/radio/src/react/__stories__/index.story.js b/packages/radio/src/react/__stories__/index.story.js
index 5225d068d7..93bf70dc63 100644
--- a/packages/radio/src/react/__stories__/index.story.js
+++ b/packages/radio/src/react/__stories__/index.story.js
@@ -11,14 +11,14 @@ const PaddingDecorator = storyFn => (
storiesOf('Radio', module)
.addDecorator(PaddingDecorator)
.add('default', _ => (
-
+
))
.add('one selected', _ => (
-
+
@@ -29,7 +29,6 @@ storiesOf('Radio', module)
value="green"
label="Colors"
subLabel="These colors are very primary"
- name="labels"
>
@@ -37,31 +36,31 @@ storiesOf('Radio', module)
))
.add('error', _ => (
-
+
))
.add('disabled', _ => (
-
+
))
.add('disabled & error', _ => (
-
+
))
- .add('controlled', _ => {
+ .add('state demo', _ => {
function StateDemo() {
const [value, setValue] = React.useState('red')
- function handleChange(evt, nextValue) {
+ function handleSelect(evt, nextValue) {
setValue(nextValue)
}
@@ -69,10 +68,8 @@ storiesOf('Radio', module)
Selected: {value}
-
-
-
+
diff --git a/packages/radio/src/react/button.js b/packages/radio/src/react/button.js
index dfdb4c46e9..beb025ac1a 100644
--- a/packages/radio/src/react/button.js
+++ b/packages/radio/src/react/button.js
@@ -1,24 +1,24 @@
import { compose, css } from 'glamor'
import PropTypes from 'prop-types'
-import React, { useState } from 'react'
+import React from 'react'
import filterReactProps from '@pluralsight/ps-design-system-filter-react-props'
import Halo from '@pluralsight/ps-design-system-halo'
import { useTheme } from '@pluralsight/ps-design-system-theme'
-import { combineFns } from '@pluralsight/ps-design-system-util'
-import { useRadioContext } from './context.js'
+
import stylesheet from '../css/index.js'
const styles = {
button: () => css(stylesheet['.psds-radio-button']),
- circle: (themeName, checked) =>
+ circle: (themeName, { checked }) =>
compose(
css(stylesheet['.psds-radio-button__circle']),
css(stylesheet[`.psds-radio-button__circle.psds-theme--${themeName}`]),
checked && css(stylesheet['.psds-radio-button__circle--checked'])
),
circleOuter: () => css(stylesheet['.psds-radio-button__circle-outer']),
- circleInner: () => css(stylesheet['.psds-radio-button__circle-inner']),
+ circleInner: (themeName, { checked }) =>
+ css(stylesheet['.psds-radio-button__circle-inner']),
halo: () => css(stylesheet['.psds-radio-button__halo']),
input: () => css(stylesheet['.psds-radio-button__input']),
label: themeName =>
@@ -28,80 +28,86 @@ const styles = {
)
}
-const isChecked = (a, b) => a === b
-
-const Button = React.forwardRef(({ value, label, ...props }, forwardedRef) => {
+const Button = React.forwardRef((props, forwardedRef) => {
const themeName = useTheme()
- const { checkedValue, onChange, disabled, error, name } = useRadioContext()
+
const ref = React.useRef()
React.useImperativeHandle(forwardedRef, () => ref.current)
const circleRef = React.useRef()
- const [isFocused, setFocus] = useState(false)
- const handleFocus = e => {
- if (disabled) return
- combineFns(() => setFocus(true), props.onFocus)(e)
- }
- const handleBlur = e => {
- if (disabled) return
- combineFns(props.onFocus, () => setFocus(false))(e)
- }
- function handleClick(e) {
- const value = e.target.value
- combineFns(onChange, props.onClick)(e, value)
- ref.current.focus()
+ function handleClick(evt) {
+ const value = evt.target.value
+ props._onClick(evt, value)
+
+ if (isFunction(props.onClick)) props.onClick(evt, value)
+ props._onFocus(evt, value)
+
+ circleRef.current.focus()
}
- const checked = isChecked(value, checkedValue)
+
+ const { _disabled, _error, _isFocused, _onFocus, _name } = props
+
return (
-