Use our Tailwind CSS Radio Button built with Angular to ensure single-option selections on your website or applications.
Radio buttons are essential for choices where only one option can be selected from a list. They guide users in making clear-cut decisions and prevent multiple selections. It's very important that radio buttons give a clear indication of the selected and non-selected state for ease of use.
Below, explore our Angular Radio Button example designed with Tailwind CSS.
You first need to import the DUIRadio Module into your application module
Code
import { DUIRadio } from "david-ui-angular"; @NgModule({ declarations: [AppComponent], imports: [BrowserModule, DUIRadio], providers: [], bootstrap: [AppComponent], }) export class AppModule {}
Preview
Code
<dui-radio name="foo" value="1" color="gray"></dui-radio>
You can disable the radio button by adding the disabled attribute to the component
Preview
Code
<dui-radio name="radio-name" label="Angular" value="1" color="gray" [disabled]="true"></dui-radio>
You can add a label to the radio button by adding the label attribute to the component
Preview
Code
<dui-radio name="radio-name" label="Angular" value="1" color="gray"></dui-radio> <dui-radio name="radio-name" label="React" value="2" color="gray"></dui-radio> <dui-radio name="radio-name" label="Vuejs" value="3" color="gray"></dui-radio>
You can use different colors of the radio component by manipulating the color attribute of the component
Preview
Code
<dui-radio name="radio-name" label="Angular" value="1" color="red"></dui-radio> <dui-radio name="radio-name" label="React" value="2" color="blue"></dui-radio> <dui-radio name="radio-name" label="Vuejs" value="3" color="green"></dui-radio>
You can turn on/off the ripple effect for the Radio
Component using ripple
attribute.
Preview
Code
<dui-radio color="gray" name="radio-ripple-effect" label="Ripple Effect On" value="1" [ripple]="true"> </dui-radio> <dui-radio color="gray" name="radio-ripple-effect" label="Ripple Effect Off" value="2" [ripple]="false"></dui-radio>
You can add custom icon for the Radio
Component when it's filled by using the dui-icon
element inside dui-radio
.
Preview
Code
<dui-radio color="gray" name="radio-custom-icon" label="Radio Custom Icon" value="2" [useCustomIcon]="true" > <dui-icon> <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" viewBox="0 0 20 20" fill="currentColor" > <path fillRule="evenodd" d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4 4 0 115.656 5.656L10 17.657l-6.828-6.829a4 4 0 010-5.656z" clipRule="evenodd" /> </svg> </dui-icon> </dui-radio>
You can disable the Radio component by passing the disabled prop to the Radio component.
Preview
Code
<dui-radio name="radio-name" label="Angular" value="1" [disabled]="true" color="gray"></dui-radio> <dui-radio name="radio-name" label="React" value="2" [disabled]="true" color="gray"></dui-radio> <dui-radio name="radio-name" label="Vuejs" value="3" [disabled]="true" color="gray"></dui-radio>
You can add any element inside dui-radio
. Here we used typography to make it look like a Link
Preview
I agree with the terms and condition
Code
<dui-radio color="gray" name="radio-name-link" value="1" > <dui-typography color="gray" variant="paragraph"> I agree with the <a href="https://www.david-ui-angular.com/docs/radio" class="text-blue-500">terms and condition</a> </dui-typography> </dui-radio>
Use the example below for a more complex usage of radio with label that contains some description.
Preview
You'll be able to login without password for 24 hours.
Code
<dui-radio color="gray" label="Remember me" name="radio-name-description" value="1"> <div> <dui-typography color="gray" variant="small" className="font-normal"> You'll be able to login without password for 24 hours. </dui-typography> </div> </dui-radio>
The following properties are available for dui-radio
Attribute | Type | Description | Default |
---|---|---|---|
label | string | radio label | '' |
color | Color | change radio color | blue |
className | string | Add custom className for radio | '' |
size | boolean | Change radio size | md |
disabled | boolean | Disable radio | false |
containerClassName | string | radio container class property | '' |
ripple | boolean | Toggle ripple effect in radio | true |
useCustomIcon | boolean | use custom icon in radio | false |