Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@ngheadlessui/radio
Advanced tools
Radio Groups give you the same functionality as native HTML radio inputs, without any of the styling. They're perfect for building out custom UIs for selectors.
Radio Groups give you the same functionality as native HTML radio inputs, without any of the styling. They're perfect for building out custom UIs for selectors.
# npm
npm install @ngheadlessui/radio
# Yarn
yarn add @ngheadlessui/radio
# import the lib into module you want to use it in
import { UiRadioModule } from '@ngheadlessui/radio';
Radio Groups are built using the headless-tab-group
, and headlessRadioOption
components.
Clicking an option will select it, and when the Radio Group is focused, the arrow keys will change the selected option.
<headless-radio-group>
<!-- You can use the headlessRadioOption as a component -->
<headlessRadioOption>Option 1</headlessRadioOption>
<headlessRadioOption>Option 2</headlessRadioOption>
<headlessRadioOption>Option 3</headlessRadioOption>
<!--or as a directive -->
<div headlessRadioOption>Option 1</div>
<div headlessRadioOption>Option 2</div>
<div headlessRadioOption>Option 3</div>
</headless-radio-group>
This is a headless component so there are no styles included by default. Instead, the components expose useful information via bound classes that you can use to apply styles yourself.
To style the checked Radio, use the selected class checked-headless-radio
, which tells you which radio is currently checked. For flexiblity.
.checked-headless-radio {
@apply bg-sky-900 bg-opacity-75 text-white;
}
To disable a radio, use the disabled input property on the headlessRadioOption
component. Disabled radio items cannot be selected with the mouse.
<headless-tab-group>
<headless-radio-group>
<!-- You can use the headlessRadioOption as a component -->
<headlessRadioOption [disabled]="true">Option 1</headlessRadioOption>
<headlessRadioOption>Option 2</headlessRadioOption>
<headlessRadioOption>Option 3</headlessRadioOption>
<!--or as a directive -->
<ng-container *ngFor="let plan of plans">
<div headlessRadioOption [disabled]="plan.name === 'monthly'">
{{ plan.name }}
</div>
</ng-container>
</headless-radio-group>
</headless-tab-group>
To style disabled radio, use the disabled class disabled-headless-radio
,
which tells you whether or not that radio option is currently disabled.
.disabled-headless-radio {
@apply text-red-300 bg-yellow-700 hover:bg-white/[0.12] hover:text-white;
}
To select a radio is checked by default, use the checkedOptionIndex="number" property on the headless-tab-group
component.
<headless-radio-group [checkedOptionIndex]="1">
<headlessRadioOption>Option 1</headlessRadioOption>
<headlessRadioOption>Option 2</headlessRadioOption>
<headlessRadioOption>Option 3</headlessRadioOption>
</headless-radio-group>
To run a function whenever the checked radio changes, listen to emissions from the (changeRadio) EventEmitter on the headless-radio-group
component. (changeRadio) emits the index ($event) of the checked radio.
<headless-radio-group (changeRadio)="listenToChangeInRadio($event)">
<headlessRadioOption>Option 1</headlessRadioOption>
<headlessRadioOption>Option 2</headlessRadioOption>
<headlessRadioOption>Option 3</headlessRadioOption>
</headless-radio-group>
The main Radio Group component.
Props | Default | Description |
---|---|---|
checkedOptionIndex | 0 | Number The index of checked radio |
(changeRadio) | EventEmitter This is fired when there is a change in checked radio |
The Radio component.
Props | Default | Description |
---|---|---|
id | undefined | String unique identifier of the radio option |
disabled | false | Boolean Whether or not selected of the Rasio option is currently disabled. |
FAQs
Radio Groups give you the same functionality as native HTML radio inputs, without any of the styling. They're perfect for building out custom UIs for selectors.
The npm package @ngheadlessui/radio receives a total of 1 weekly downloads. As such, @ngheadlessui/radio popularity was classified as not popular.
We found that @ngheadlessui/radio demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.