Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F111656040
RadioGroup.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, May 4, 05:04
Size
3 KB
Mime Type
text/x-java
Expires
Tue, May 6, 05:04 (1 d, 18 h)
Engine
blob
Format
Raw Data
Handle
25966773
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
RadioGroup.js
View Options
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["actions", "children", "defaultValue", "name", "onChange", "value"];
import * as React from 'react';
import PropTypes from 'prop-types';
import FormGroup from '../FormGroup';
import useForkRef from '../utils/useForkRef';
import useControlled from '../utils/useControlled';
import RadioGroupContext from './RadioGroupContext';
import useId from '../utils/useId';
import { jsx as _jsx } from "react/jsx-runtime";
const RadioGroup = /*#__PURE__*/React.forwardRef(function RadioGroup(props, ref) {
const {
// private
// eslint-disable-next-line react/prop-types
actions,
children,
defaultValue,
name: nameProp,
onChange,
value: valueProp
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const rootRef = React.useRef(null);
const [value, setValueState] = useControlled({
controlled: valueProp,
default: defaultValue,
name: 'RadioGroup'
});
React.useImperativeHandle(actions, () => ({
focus: () => {
let input = rootRef.current.querySelector('input:not(:disabled):checked');
if (!input) {
input = rootRef.current.querySelector('input:not(:disabled)');
}
if (input) {
input.focus();
}
}
}), []);
const handleRef = useForkRef(ref, rootRef);
const name = useId(nameProp);
const contextValue = React.useMemo(() => ({
name,
onChange(event) {
setValueState(event.target.value);
if (onChange) {
onChange(event, event.target.value);
}
},
value
}), [name, onChange, setValueState, value]);
return /*#__PURE__*/_jsx(RadioGroupContext.Provider, {
value: contextValue,
children: /*#__PURE__*/_jsx(FormGroup, _extends({
role: "radiogroup",
ref: handleRef
}, other, {
children: children
}))
});
});
process.env.NODE_ENV !== "production" ? RadioGroup.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the d.ts file and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* The default value. Use when the component is not controlled.
*/
defaultValue: PropTypes.any,
/**
* The name used to reference the value of the control.
* If you don't provide this prop, it falls back to a randomly generated name.
*/
name: PropTypes.string,
/**
* Callback fired when a radio button is selected.
*
* @param {React.ChangeEvent<HTMLInputElement>} event The event source of the callback.
* @param {string} value The value of the selected radio button.
* You can pull out the new value by accessing `event.target.value` (string).
*/
onChange: PropTypes.func,
/**
* Value of the selected radio button. The DOM API casts this to a string.
*/
value: PropTypes.any
} : void 0;
export default RadioGroup;
Event Timeline
Log In to Comment