forked from stimulus-components/stimulus-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Add Stimulus Radio Uncheck component #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elalemanyo
wants to merge
18
commits into
master
Choose a base branch
from
feature/add_radio_uncheck
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6eef381
Add Stimulus Radio Uncheck component with initial implementation
elalemanyo 9782dd3
Add Stimulus dependency for Radio Uncheck component in pnpm-lock.yaml
elalemanyo 9cacd42
Merge branch 'master' into feature/add_radio_uncheck
elalemanyo a684ba1
Merge branch 'master' into feature/add_radio_uncheck
elalemanyo 600169d
Add radio-uncheck component to package.json
elalemanyo f2a41c5
Add RadioUncheck component for form functionality
elalemanyo 5b7f73f
Add documentation for Radio Uncheck Stimulus controller
elalemanyo ce5e099
Register RadioUncheck component in Stimulus client
elalemanyo 09720e6
Bump version of radio-uncheck component to 1.0.0
elalemanyo 8862dbc
Fix data attribute alignment in RadioUncheck demo component
elalemanyo ed49a02
Fix self-closing tags in Radio Uncheck documentation example
elalemanyo 70d9907
Update components/radio-uncheck/CHANGELOG.md
elalemanyo 9755d20
Update docs/content/docs/stimulus-radio-uncheck.md
elalemanyo 3b653fd
Update docs/components/content/Demo/RadioUncheck.vue
elalemanyo 22f4ed0
Update docs/components/content/Demo/RadioUncheck.vue
elalemanyo 42d4fc5
Update docs/components/content/Demo/RadioUncheck.vue
elalemanyo abd03fc
Update docs/content/docs/stimulus-radio-uncheck.md
elalemanyo 2632a0e
Update radio button labels to include '#' for clarity
elalemanyo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Changelog | ||
|
|
||
| ## [1.0.0] - 2024-12-30 | ||
|
|
||
| ### Added | ||
|
|
||
| - Adding controller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Stimulus Radio Uncheck | ||
|
|
||
| ## Getting started | ||
|
|
||
| A Stimulus controller for unchecking all radio buttons in a group. | ||
|
|
||
| ## 📚 Documentation | ||
|
|
||
| See [stimulus-radio-uncheck documentation](https://www.stimulus-components.com/docs/stimulus-radio-uncheck/). | ||
|
|
||
| ## 👷♂️ Contributing | ||
|
|
||
| Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome. | ||
|
|
||
| ## 📝 License | ||
|
|
||
| This project is released under the [MIT](http://opensource.org/licenses/MIT) license. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
|
|
||
| <title>Stimulus Radio Uncheck All</title> | ||
|
|
||
| <script type="module"> | ||
| import "../app.css" | ||
| import { Application } from "@hotwired/stimulus" | ||
| import RadioUncheck from "./src/index" | ||
|
|
||
| const application = Application.start() | ||
| application.register("radio-uncheck", RadioUncheck) | ||
| </script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div class="relative h-full max-w-5xl mx-auto px-4"> | ||
| <section class="mt-16"> | ||
| <form data-controller="radio-uncheck" class="space-y-4"> | ||
| <div class="flex items-center gap-x-3"> | ||
| <input | ||
| data-radio-uncheck-target="radio" | ||
| id="team-1" | ||
| name="team" | ||
| type="radio" | ||
| class="h-4 w-4 border-gray-300 text-orange-600 focus:ring-orange-600" | ||
| /> | ||
| <label for="team-1" class="block text-sm/6 font-medium text-gray-900">Team 1</label> | ||
| </div> | ||
| <div class="flex items-center gap-x-3"> | ||
| <input | ||
| data-radio-uncheck-target="radio" | ||
| id="team-2" | ||
| name="team" | ||
| type="radio" | ||
| class="h-4 w-4 border-gray-300 text-orange-600 focus:ring-orange-600" | ||
| /> | ||
| <label for="team-2" class="block text-sm/6 font-medium text-gray-900">Team 2</label> | ||
| </div> | ||
| <div class="flex items-center gap-x-3"> | ||
| <input | ||
| data-radio-uncheck-target="radio" | ||
| id="team-3" | ||
| name="team" | ||
| type="radio" | ||
| class="h-4 w-4 border-gray-300 text-orange-600 focus:ring-orange-600" | ||
| /> | ||
| <label for="team-3" class="block text-sm/6 font-medium text-gray-900">Team 3</label> | ||
| </div> | ||
| <div> | ||
| <button | ||
| type="button" | ||
| data-action="radio-uncheck#uncheck" | ||
| class="rounded-md bg-orange-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-orange-500" | ||
| > | ||
| Uncheck | ||
| </button> | ||
| </div> | ||
| </form> | ||
| </section> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "name": "@stimulus-components/radio-uncheck", | ||
| "version": "1.0.0", | ||
| "description": "A Stimulus controller to uncheck all radio buttons in a group.", | ||
| "keywords": [ | ||
| "stimulus", | ||
| "stimulusjs", | ||
| "stimulus controller", | ||
| "radio", | ||
| "radio-uncheck" | ||
| ], | ||
| "repository": "git@github.com:stimulus-components/stimulus-components.git", | ||
| "bugs": { | ||
| "url": "https://github.com/stimulus-components/stimulus-components/issues" | ||
| }, | ||
| "author": "Guillaume Briday <guillaumebriday@gmail.com>", | ||
| "license": "MIT", | ||
| "homepage": "https://github.com/stimulus-components/stimulus-components", | ||
| "private": false, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "main": "dist/stimulus-radio-uncheck.umd.js", | ||
| "module": "dist/stimulus-radio-uncheck.mjs", | ||
| "types": "dist/types/index.d.ts", | ||
| "scripts": { | ||
| "types": "tsc --noEmit false --declaration true --emitDeclarationOnly true --outDir dist/types", | ||
| "dev": "vite", | ||
| "build": "vite build && pnpm run types", | ||
| "version": "pnpm run build", | ||
| "np": "np --no-2fa" | ||
| }, | ||
| "peerDependencies": { | ||
| "@hotwired/stimulus": "^3" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * @jest-environment jsdom | ||
| */ | ||
|
|
||
| import { beforeEach, describe, it, expect } from "vitest" | ||
| import { Application } from "@hotwired/stimulus" | ||
| import RadioUncheck from "../src/index" | ||
|
|
||
| const startStimulus = (): void => { | ||
| const application = Application.start() | ||
| application.register("radio-uncheck", RadioUncheck) | ||
| } | ||
|
|
||
| beforeEach((): void => { | ||
| startStimulus() | ||
|
|
||
| document.body.innerHTML = ` | ||
| <form data-controller="radio-uncheck"> | ||
| <input data-radio-uncheck-target="radio" id="team-1" name="team" type="radio"> | ||
| <label for="team-1">Team 1</label> | ||
|
|
||
| <input data-radio-uncheck-target="radio" id="team-2" name="team" type="radio"> | ||
| <label for="team-2">Team 2</label> | ||
|
|
||
| <input data-radio-uncheck-target="radio" id="team-3" name="team" type="radio"> | ||
| <label for="team-3">Team 3</label> | ||
|
|
||
| <button type="button" data-action="radio-uncheck#uncheck">Uncheck</button> | ||
| </form> | ||
| ` | ||
| }) | ||
|
|
||
| describe("#uncheck", () => { | ||
| it("should uncheck all radio buttons", (): void => { | ||
| const uncheckButton: HTMLButtonElement = document.querySelector("[data-action='radio-uncheck#uncheck']") | ||
| const radios: HTMLInputElement[] = [ | ||
| document.querySelector("#team-1"), | ||
| document.querySelector("#team-2"), | ||
| document.querySelector("#team-3"), | ||
| ] | ||
|
|
||
| radios.forEach((radioToCheck) => { | ||
| radioToCheck.checked = true | ||
| uncheckButton.click() | ||
| radios.forEach((radio) => { | ||
| expect(radio.checked).toBe(false) | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { Controller } from "@hotwired/stimulus" | ||
|
|
||
| export default class RadioUncheckApp extends Controller { | ||
| declare hasRadioTarget: boolean | ||
| declare radioTargets: HTMLInputElement[] | ||
|
|
||
| static targets = ["radio"] | ||
|
|
||
| uncheck(): void { | ||
| if (!this.hasRadioTarget) return | ||
|
|
||
| this.radioTargets.forEach((radio) => { | ||
| radio.checked = false | ||
| radio.dispatchEvent(new Event("change", { bubbles: true })) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** @type {import('tailwindcss').Config} */ | ||
| export default { | ||
| content: ["./index.html", "./src/**/*.{js,ts}"], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": "../../tsconfig.json" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { resolve } from "path" | ||
| import { defineConfig } from "vite" | ||
|
|
||
| export default defineConfig({ | ||
| esbuild: { | ||
| minifyIdentifiers: false, | ||
| }, | ||
| build: { | ||
| lib: { | ||
| entry: resolve(__dirname, "src/index.ts"), | ||
| name: "StimulusRadioUncheck", | ||
| fileName: "stimulus-radio-uncheck", | ||
| }, | ||
| rollupOptions: { | ||
| external: ["@hotwired/stimulus"], | ||
| output: { | ||
| globals: { | ||
| "@hotwired/stimulus": "Stimulus", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <template> | ||
| <Block title="Radio Uncheck"> | ||
| <form data-controller="radio-uncheck" class="space-y-4"> | ||
| <div class="flex items-center gap-x-3"> | ||
| <input | ||
| id="team-1" | ||
| data-radio-uncheck-target="radio" | ||
| name="team" | ||
| type="radio" | ||
| class="h-4 w-4 border-gray-300 text-orange-600 focus:ring-orange-600" | ||
| /> | ||
| <label for="team-1" class="block text-sm/6 font-medium text-gray-900">Team 1</label> | ||
| </div> | ||
| <div class="flex items-center gap-x-3"> | ||
| <input | ||
| id="team-2" | ||
| data-radio-uncheck-target="radio" | ||
| name="team" | ||
| type="radio" | ||
| class="h-4 w-4 border-gray-300 text-orange-600 focus:ring-orange-600" | ||
|
elalemanyo marked this conversation as resolved.
Outdated
|
||
| /> | ||
| <label for="team-2" class="block text-sm/6 font-medium text-gray-900">Team 2</label> | ||
| </div> | ||
| <div class="flex items-center gap-x-3"> | ||
| <input | ||
| id="team-3" | ||
| data-radio-uncheck-target="radio" | ||
| name="team" | ||
| type="radio" | ||
| class="h-4 w-4 border-gray-300 text-orange-600 focus:ring-orange-600" | ||
|
elalemanyo marked this conversation as resolved.
Outdated
|
||
| /> | ||
| <label for="team-3" class="block text-sm/6 font-medium text-gray-900">Team 3</label> | ||
| </div> | ||
| <div> | ||
| <button | ||
| type="button" | ||
| data-action="radio-uncheck#uncheck" | ||
| class="rounded-md bg-orange-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-orange-500" | ||
| > | ||
| Uncheck | ||
| </button> | ||
| </div> | ||
| </form> | ||
| </Block> | ||
| </template> | ||
|
|
||
| <script setup> | ||
| import Block from "@/components/UI/Block.vue" | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --- | ||
| title: Radio Uncheck | ||
| description: A Stimulus controller to uncheck radio buttons. | ||
|
elalemanyo marked this conversation as resolved.
Outdated
|
||
| package: radio-uncheck | ||
| packagePath: "@stimulus-components/radio-uncheck" | ||
| isNew: true | ||
| --- | ||
|
|
||
| ## Installation | ||
|
|
||
| :installation-block{:package="package" :packagePath="packagePath" controllerName="radio-uncheck"} | ||
|
|
||
| ## Examples | ||
|
|
||
| :radio-uncheck | ||
|
|
||
| ## Usage | ||
|
|
||
| ::code-block{tabName="app/views/index.html"} | ||
|
|
||
| ```html | ||
| <div data-controller="radio-uncheck"> | ||
| <input type="radio" name="radio" value="1" data-radio-uncheck-target="input" /> | ||
| <label for="radio-1">Radio 1</label> | ||
| <input type="radio" name="radio" value="2" data-radio-uncheck-target="input" /> | ||
| <label for="radio-2">Radio 2</label> | ||
| <input type="radio" name="radio" value="3" data-radio-uncheck-target="input" /> | ||
| <label for="radio-3">Radio 3</label> | ||
|
|
||
| <button data-action="radio-uncheck#uncheck">Uncheck</button> | ||
| </div> | ||
| ``` | ||
|
|
||
| :: | ||
|
|
||
| ## Extending Controller | ||
|
|
||
| ::extending-controller | ||
| ::code-block{tabName="app/javascript/controllers/radio_uncheck_controller.js"} | ||
|
|
||
| ```js | ||
| import RadioUncheck from "@stimulus-components/radio-uncheck" | ||
|
|
||
| export default class extends RadioUncheckController { | ||
| connect() { | ||
| super.connect() | ||
| console.log("Do what you want here.") | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| :: | ||
| :: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.