Refactor #3922 - For RadioButton

pull/3938/head
Tuğçe Küçükoğlu 2023-05-05 18:20:34 +03:00
parent 26cbc4dc4c
commit 7000136a6a
4 changed files with 70 additions and 5 deletions

View File

@ -58,6 +58,12 @@ const RadioButtonProps = [
type: 'string',
default: 'null',
description: 'Used to define a string that labels the element.'
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
}
];

View File

@ -45,6 +45,7 @@ import { PanelMenuPassThroughOptions } from '../panelmenu';
import { PasswordPassThroughOptions } from '../password';
import { ProgressBarPassThroughOptions } from '../progressbar';
import { ProgressSpinnerPassThroughOptions } from '../progressspinner';
import { RadioButtonPassThroughOptions } from '../radiobutton';
import { ScrollPanelPassThroughOptions } from '../scrollpanel';
import { ScrollTopPassThroughOptions } from '../scrolltop';
import { SidebarPassThroughOptions } from '../sidebar';
@ -126,6 +127,7 @@ interface PrimeVuePTOptions {
password?: PasswordPassThroughOptions;
progressbar?: ProgressBarPassThroughOptions;
progressspinner?: ProgressSpinnerPassThroughOptions;
radiobutton?: RadioButtonPassThroughOptions;
scrollpanel?: ScrollPanelPassThroughOptions;
scrolltop?: ScrollTopPassThroughOptions;
sidebar?: SidebarPassThroughOptions;

View File

@ -10,6 +10,61 @@
import { InputHTMLAttributes } from 'vue';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type RadioButtonPassThroughOptionType = RadioButtonPassThroughAttributes | ((options: RadioButtonPassThroughMethodOptions) => RadioButtonPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface RadioButtonPassThroughMethodOptions {
props: RadioButtonProps;
state: RadioButtonState;
}
/**
* Custom passthrough(pt) options.
* @see {@link RadioButtonProps.pt}
*/
export interface RadioButtonPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: RadioButtonPassThroughOptionType;
/**
* Uses to pass attributes to the input's DOM element.
*/
input?: RadioButtonPassThroughOptionType;
/**
* Uses to pass attributes to the icon's DOM element.
*/
icon?: RadioButtonPassThroughOptionType;
/**
* Uses to pass attributes to the hidden accessible DOM element wrapper.
*/
hiddenInputWrapper?: RadioButtonPassThroughOptionType;
/**
* Uses to pass attributes to the hidden accessible DOM element.
*/
hiddenInput?: RadioButtonPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface RadioButtonPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in RadioButton component.
*/
export interface RadioButtonState {
/**
* Current focused state as a boolean.
* @defaultValue false
*/
focused: boolean;
}
/**
* Defines valid properties in RadioButton component.
*/

View File

@ -1,6 +1,6 @@
<template>
<div :class="containerClass" @click="onClick($event)">
<div class="p-hidden-accessible">
<div :class="containerClass" @click="onClick($event)" v-bind="ptm('root')">
<div class="p-hidden-accessible" v-bind="ptm('hiddenInputWrapper')">
<input
ref="input"
:id="inputId"
@ -15,20 +15,22 @@
:aria-label="ariaLabel"
@focus="onFocus"
@blur="onBlur"
v-bind="inputProps"
v-bind="ptm('hiddenInput')"
/>
</div>
<div ref="box" :class="['p-radiobutton-box', { 'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused }]">
<div class="p-radiobutton-icon"></div>
<div ref="box" :class="['p-radiobutton-box', { 'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused }]" v-bind="{ ...inputProps, ...ptm('input') }">
<div class="p-radiobutton-icon" v-bind="ptm('icon')"></div>
</div>
</div>
</template>
<script>
import BaseComponent from 'primevue/basecomponent';
import { ObjectUtils } from 'primevue/utils';
export default {
name: 'RadioButton',
extends: BaseComponent,
emits: ['click', 'update:modelValue', 'change', 'focus', 'blur'],
props: {
value: null,