Update #3965 - For RadioButton
parent
4a9b279db1
commit
e18b9b0b0b
|
@ -0,0 +1,112 @@
|
|||
<script>
|
||||
import BaseComponent from 'primevue/basecomponent';
|
||||
import { useStyle } from 'primevue/usestyle';
|
||||
|
||||
const styles = `
|
||||
.p-radiobutton {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
.p-radiobutton.p-radiobutton-disabled {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.p-radiobutton-box {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.p-radiobutton-icon {
|
||||
-webkit-backface-visibility: hidden;
|
||||
backface-visibility: hidden;
|
||||
transform: translateZ(0) scale(.1);
|
||||
border-radius: 50%;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.p-radiobutton-box.p-highlight .p-radiobutton-icon {
|
||||
transform: translateZ(0) scale(1.0, 1.0);
|
||||
visibility: visible;
|
||||
}
|
||||
`;
|
||||
|
||||
const classes = {
|
||||
root: ({ instance, props }) => [
|
||||
'p-radiobutton p-component',
|
||||
{
|
||||
'p-radiobutton-checked': instance.checked,
|
||||
'p-radiobutton-disabled': props.disabled,
|
||||
'p-radiobutton-focused': instance.focused
|
||||
}
|
||||
],
|
||||
hiddenInputWrapper: 'p-hidden-accessible',
|
||||
input: ({ instance, props }) => [
|
||||
'p-radiobutton-box',
|
||||
{
|
||||
'p-highlight': instance.checked,
|
||||
'p-disabled': props.disabled,
|
||||
'p-focus': instance.focused
|
||||
}
|
||||
],
|
||||
icon: 'p-radiobutton-icon'
|
||||
};
|
||||
|
||||
const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_radiobutton_style', manual: true });
|
||||
|
||||
export default {
|
||||
name: 'BaseRadioButton',
|
||||
extends: BaseComponent,
|
||||
props: {
|
||||
value: null,
|
||||
modelValue: null,
|
||||
name: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
inputId: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
inputClass: {
|
||||
type: [String, Object],
|
||||
default: null
|
||||
},
|
||||
inputStyle: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
inputProps: {
|
||||
type: null,
|
||||
default: null
|
||||
},
|
||||
'aria-labelledby': {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
'aria-label': {
|
||||
type: String,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
css: {
|
||||
classes
|
||||
},
|
||||
watch: {
|
||||
isUnstyled: {
|
||||
immediate: true,
|
||||
handler(newValue) {
|
||||
!newValue && loadStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -110,6 +110,16 @@ export interface RadioButtonProps {
|
|||
* Establishes a string value that labels the component.
|
||||
*/
|
||||
'aria-label'?: string | undefined;
|
||||
/**
|
||||
* Uses to pass attributes to DOM elements inside the component.
|
||||
* @type {RadioButtonPassThroughMethodOptions}
|
||||
*/
|
||||
pt?: RadioButtonPassThroughMethodOptions;
|
||||
/**
|
||||
* When enabled, it removes component related styles in the core.
|
||||
* @defaultValue false
|
||||
*/
|
||||
unstyled?: boolean;
|
||||
}
|
||||
|
||||
export interface RadioButtonSlots {}
|
||||
|
|
|
@ -1,73 +1,22 @@
|
|||
<template>
|
||||
<div :class="containerClass" @click="onClick($event)" v-bind="ptm('root')">
|
||||
<div class="p-hidden-accessible" v-bind="ptm('hiddenInputWrapper')">
|
||||
<input
|
||||
ref="input"
|
||||
:id="inputId"
|
||||
type="radio"
|
||||
:class="inputClass"
|
||||
:style="inputStyle"
|
||||
:name="name"
|
||||
:checked="checked"
|
||||
:disabled="disabled"
|
||||
:value="value"
|
||||
:aria-labelledby="ariaLabelledby"
|
||||
:aria-label="ariaLabel"
|
||||
@focus="onFocus"
|
||||
@blur="onBlur"
|
||||
v-bind="ptm('hiddenInput')"
|
||||
/>
|
||||
<div :class="cx('root')" @click="onClick($event)" v-bind="ptm('root')">
|
||||
<div :class="cx('hiddenInputWrapper')" :style="sx('hiddenAccessible', isUnstyled)" v-bind="ptm('hiddenInputWrapper')" :data-p-hidden-accessible="true">
|
||||
<input ref="input" :id="inputId" type="radio" :name="name" :checked="checked" :disabled="disabled" :value="value" :aria-labelledby="ariaLabelledby" :aria-label="ariaLabel" @focus="onFocus" @blur="onBlur" v-bind="ptm('hiddenInput')" />
|
||||
</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 ref="box" :class="[cx('input'), inputClass]" :style="inputStyle" v-bind="{ ...inputProps, ...ptm('input') }" :data-p-highlight="checked" :data-p-disabled="disabled" :data-p-focused="focused">
|
||||
<div :class="cx('icon')" v-bind="ptm('icon')"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BaseComponent from 'primevue/basecomponent';
|
||||
import { ObjectUtils } from 'primevue/utils';
|
||||
import BaseRadioButton from './BaseRadioButton.vue';
|
||||
|
||||
export default {
|
||||
name: 'RadioButton',
|
||||
extends: BaseComponent,
|
||||
extends: BaseRadioButton,
|
||||
emits: ['click', 'update:modelValue', 'change', 'focus', 'blur'],
|
||||
props: {
|
||||
value: null,
|
||||
modelValue: null,
|
||||
name: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
inputId: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
inputClass: {
|
||||
type: [String, Object],
|
||||
default: null
|
||||
},
|
||||
inputStyle: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
inputProps: {
|
||||
type: null,
|
||||
default: null
|
||||
},
|
||||
'aria-labelledby': {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
'aria-label': {
|
||||
type: String,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
focused: false
|
||||
|
@ -97,16 +46,6 @@ export default {
|
|||
computed: {
|
||||
checked() {
|
||||
return this.modelValue != null && ObjectUtils.equals(this.modelValue, this.value);
|
||||
},
|
||||
containerClass() {
|
||||
return [
|
||||
'p-radiobutton p-component',
|
||||
{
|
||||
'p-radiobutton-checked': this.checked,
|
||||
'p-radiobutton-disabled': this.disabled,
|
||||
'p-radiobutton-focused': this.focused
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue