{"id":13422118,"url":"https://github.com/chenglou/react-radio-group","last_synced_at":"2025-05-15T20:01:37.254Z","repository":{"id":9738226,"uuid":"11699056","full_name":"chenglou/react-radio-group","owner":"chenglou","description":"Better radio buttons.","archived":false,"fork":false,"pushed_at":"2023-11-13T14:12:13.000Z","size":43,"stargazers_count":442,"open_issues_count":16,"forks_count":76,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-14T02:26:30.014Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chenglou.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2013-07-27T03:02:51.000Z","updated_at":"2024-04-17T14:57:54.528Z","dependencies_parsed_at":"2024-04-17T14:57:53.052Z","dependency_job_id":"9bee2173-8e69-4b49-9ef6-73a642e70e1f","html_url":"https://github.com/chenglou/react-radio-group","commit_stats":{"total_commits":60,"total_committers":13,"mean_commits":4.615384615384615,"dds":"0.41666666666666663","last_synced_commit":"1430fa968b770cfe00dadb93f56a04db6970d8d5"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenglou%2Freact-radio-group","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenglou%2Freact-radio-group/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenglou%2Freact-radio-group/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenglou%2Freact-radio-group/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenglou","download_url":"https://codeload.github.com/chenglou/react-radio-group/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247761052,"owners_count":20991532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T23:00:37.284Z","updated_at":"2025-04-08T01:37:36.871Z","avatar_url":"https://github.com/chenglou.png","language":"JavaScript","funding_links":[],"categories":["UI Components","Uncategorized","Demos","\u003csummary\u003eUI Components\u003c/summary\u003e"],"sub_categories":["Form Components","Uncategorized"],"readme":"# [React](http://facebook.github.io/react/)-radio-group\n\n```\nnpm install react-radio-group\n```\n\nThen either `import {RadioGroup, Radio} from 'react-radio-group'` or add `node_modules/react-radio-group/umd/index.js` into your HTML file (exports the `RadioGroup` global which contains both, the RadioGroup and Radio component.).\n\n## What This Solves\nThis is your average radio buttons group:\n\n```js\n\u003cform\u003e\n  \u003cinput type=\"radio\" name=\"fruit\" value=\"apple\" /\u003eApple\n  \u003cinput type=\"radio\" name=\"fruit\" value=\"orange\" /\u003eOrange\n  \u003cinput type=\"radio\" name=\"fruit\" value=\"watermelon\" /\u003eWatermelon\n\u003c/form\u003e\n```\n\nA few problems:\n- Repetitive fields (`name`, `type`, `checked`, `onChange`).\n- Hard to set the checked value. You need to put e.g. `checked={'apple' === this.state.selectedFruitName}` on every input.\n- Hard to retrieve the selected value.\n\nHere's a better version (full example [here](https://github.com/chenglou/react-radio-group/blob/67a2bcdc7f3d0c8cb4d7762f82558d75c9592ea9/example/example.jsx))\n\n```js\n\u003cRadioGroup name=\"fruit\" selectedValue={this.state.selectedValue} onChange={this.handleChange}\u003e\n  \u003cRadio value=\"apple\" /\u003eApple\n  \u003cRadio value=\"orange\" /\u003eOrange\n  \u003cRadio value=\"watermelon\" /\u003eWatermelon\n\u003c/RadioGroup\u003e\n```\n\nRepetitive fields are either lifted onto the `RadioGroup` wrapper or already implicitly set on the `Radio` component, which is a simple wrapper around the radio `input`.\n\n## Formal API\n#### \u0026lt;RadioGroup /\u003e\nExposes [5 optional props](https://github.com/chenglou/react-radio-group/blob/67a2bcdc7f3d0c8cb4d7762f82558d75c9592ea9/index.jsx#L34-L46):\n- `name: String`: what you'd normally put on the radio inputs themselves.\n- `selectedValue: String | Number | Boolean`: the currently selected value. This will be used to compare against the values on the `Radio` components to select the right one.\n- `onChange: Function`: will be passed the newly selected value.\n- `Component: String | React Component`: defaults to `\"div\"`, defines what tag or component is used for rendering the `RadioGroup`\n- `children: Node`: define your `Radio`s and any other components. Each `Radio` component (a thin wrapper around `input`) within a `RadioGroup` will have some fields like `type`, `name` and `checked` prefilled.\n\n#### \u0026lt;Radio /\u003e\nAny prop you pass onto it will be transferred to the actual `input` under the hood. `Radio` components cannot be used outside a `RadioGroup`\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenglou%2Freact-radio-group","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenglou%2Freact-radio-group","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenglou%2Freact-radio-group/lists"}