mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(RadioGroup): add icon-size prop (#4529)
This commit is contained in:
parent
6e5e2f22a9
commit
314cfa6a14
@ -76,10 +76,12 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
|
|||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const iconSize = this.iconSize || (this.parent && this.parent.iconSize);
|
||||||
|
|
||||||
const Children = [
|
const Children = [
|
||||||
<div
|
<div
|
||||||
class={bem('icon', [this.shape, { disabled: this.isDisabled, checked }])}
|
class={bem('icon', [this.shape, { disabled: this.isDisabled, checked }])}
|
||||||
style={{ fontSize: addUnit(this.iconSize) }}
|
style={{ fontSize: addUnit(iconSize) }}
|
||||||
>
|
>
|
||||||
{CheckIcon}
|
{CheckIcon}
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,7 +8,8 @@ export default createComponent({
|
|||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: null,
|
value: null,
|
||||||
disabled: Boolean
|
disabled: Boolean,
|
||||||
|
iconSize: [Number, String]
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -125,6 +125,7 @@ export default {
|
|||||||
|------|------|------|------|------|
|
|------|------|------|------|------|
|
||||||
| v-model | Name of checked radio | *any* | - | - |
|
| v-model | Name of checked radio | *any* | - | - |
|
||||||
| disabled | Disable all radios | *boolean* | `false` | - |
|
| disabled | Disable all radios | *boolean* | `false` | - |
|
||||||
|
| icon-size | Icon size of all radios | *string \| number* | `20px` | 2.2.3 |
|
||||||
|
|
||||||
### Radio Events
|
### Radio Events
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ export default {
|
|||||||
| name | 标识符 | *any* | - | - |
|
| name | 标识符 | *any* | - | - |
|
||||||
| shape | 形状,可选值为 `square` | *string* | `round` | - |
|
| shape | 形状,可选值为 `square` | *string* | `round` | - |
|
||||||
| disabled | 是否为禁用状态 | *boolean* | `false` | - |
|
| disabled | 是否为禁用状态 | *boolean* | `false` | - |
|
||||||
| icon-size | 图标大小,默认单位为`px` | *string \| number* | `20px` | - |
|
| icon-size | 当前单选框的图标大小,默认单位为`px` | *string \| number* | `20px` | - |
|
||||||
| label-disabled | 是否禁用文本内容点击 | *boolean* | `false` | - |
|
| label-disabled | 是否禁用文本内容点击 | *boolean* | `false` | - |
|
||||||
| label-position | 文本位置,可选值为 `left` | *string* | `right` | - |
|
| label-position | 文本位置,可选值为 `left` | *string* | `right` | - |
|
||||||
| checked-color | 选中状态颜色 | *string* | `#1989fa` | - |
|
| checked-color | 选中状态颜色 | *string* | `#1989fa` | - |
|
||||||
@ -129,6 +129,7 @@ export default {
|
|||||||
|------|------|------|------|------|
|
|------|------|------|------|------|
|
||||||
| v-model | 当前选中项的标识符 | *any* | - | - |
|
| v-model | 当前选中项的标识符 | *any* | - | - |
|
||||||
| disabled | 是否禁用所有单选框 | *boolean* | `false` | - |
|
| disabled | 是否禁用所有单选框 | *boolean* | `false` | - |
|
||||||
|
| icon-size | 所有单选框的图标大小,默认单位为`px` | *string \| number* | `20px` | 2.2.3 |
|
||||||
|
|
||||||
### Radio Events
|
### Radio Events
|
||||||
|
|
||||||
|
18
src/radio/test/__snapshots__/index.spec.js.snap
Normal file
18
src/radio/test/__snapshots__/index.spec.js.snap
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`icon-size prop 1`] = `
|
||||||
|
<div role="radiogroup" class="van-radio-group">
|
||||||
|
<div role="radio" tabindex="0" aria-checked="true" class="van-radio">
|
||||||
|
<div class="van-radio__icon van-radio__icon--round van-radio__icon--checked" style="font-size: 10rem;"><i class="van-icon van-icon-success">
|
||||||
|
<!----></i></div><span class="van-radio__label">label</span>
|
||||||
|
</div>
|
||||||
|
<div role="radio" tabindex="0" aria-checked="true" class="van-radio">
|
||||||
|
<div class="van-radio__icon van-radio__icon--round van-radio__icon--checked" style="font-size: 10rem;"><i class="van-icon van-icon-success">
|
||||||
|
<!----></i></div><span class="van-radio__label">label</span>
|
||||||
|
</div>
|
||||||
|
<div role="radio" tabindex="0" aria-checked="true" class="van-radio">
|
||||||
|
<div class="van-radio__icon van-radio__icon--round van-radio__icon--checked" style="font-size: 5rem;"><i class="van-icon van-icon-success">
|
||||||
|
<!----></i></div><span class="van-radio__label">label</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
@ -1,25 +1,25 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
import Radio from '..';
|
import Radio from '..';
|
||||||
import RadioGroup from '../../radio-group';
|
import RadioGroup from '../../radio-group';
|
||||||
import { mount } from '../../../test/utils';
|
import { mount } from '../../../test/utils';
|
||||||
|
|
||||||
|
Vue.use(Radio);
|
||||||
|
Vue.use(RadioGroup);
|
||||||
|
|
||||||
test('radio-group change', () => {
|
test('radio-group change', () => {
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
template: `
|
template: `
|
||||||
<radio-group v-model="result" @change="$emit('change', $event)">
|
<van-radio-group v-model="result" @change="$emit('change', $event)">
|
||||||
<radio
|
<van-radio
|
||||||
v-for="item in list"
|
v-for="item in list"
|
||||||
:key="item"
|
:key="item"
|
||||||
:name="item"
|
:name="item"
|
||||||
:disabled="item === 'd'"
|
:disabled="item === 'd'"
|
||||||
>
|
>
|
||||||
label
|
label
|
||||||
</radio>
|
</van-radio>
|
||||||
</radio-group>
|
</van-radio-group>
|
||||||
`,
|
`,
|
||||||
components: {
|
|
||||||
Radio,
|
|
||||||
RadioGroup
|
|
||||||
},
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
result: 'a',
|
result: 'a',
|
||||||
@ -47,20 +47,16 @@ test('radio-group change', () => {
|
|||||||
test('radio group disabled', () => {
|
test('radio group disabled', () => {
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
template: `
|
template: `
|
||||||
<radio-group v-model="result" disabled @change="$emit('change', $event)">
|
<van-radio-group v-model="result" disabled @change="$emit('change', $event)">
|
||||||
<radio
|
<van-radio
|
||||||
v-for="item in list"
|
v-for="item in list"
|
||||||
:key="item"
|
:key="item"
|
||||||
:name="item"
|
:name="item"
|
||||||
>
|
>
|
||||||
label
|
label
|
||||||
</radio>
|
</van-radio>
|
||||||
</radio-group>
|
</van-radio-group>
|
||||||
`,
|
`,
|
||||||
components: {
|
|
||||||
Radio,
|
|
||||||
RadioGroup
|
|
||||||
},
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
result: 'a',
|
result: 'a',
|
||||||
@ -74,3 +70,17 @@ test('radio group disabled', () => {
|
|||||||
|
|
||||||
expect(wrapper.emitted('change')).toBeFalsy();
|
expect(wrapper.emitted('change')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('icon-size prop', () => {
|
||||||
|
const wrapper = mount({
|
||||||
|
template: `
|
||||||
|
<van-radio-group icon-size="10rem">
|
||||||
|
<van-radio>label</van-radio>
|
||||||
|
<van-radio>label</van-radio>
|
||||||
|
<van-radio icon-size="5rem">label</van-radio>
|
||||||
|
</van-radio-group>
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user