Skip to content

Commit

Permalink
fix(radio): 修复 radio-group 的 text-position 属性响应式问题 (#2572)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasayw authored Sep 21, 2023
1 parent 84058cd commit 5f56359
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
12 changes: 12 additions & 0 deletions src/packages/__VUE/radio/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
.nut-radio {
&__label {
color: $dark-color;

&--disabled {
color: $radio-label-disable-color;
}
}

&__button {
background: $dark-background;
color: $dark-color;

&--disabled {
color: $radio-label-disable-color;
border: 1px solid $radio-label-disable-color;
}
}
}
}

.nut-radio {
display: flex;
align-items: center;
Expand All @@ -27,6 +31,8 @@
}

&--reverse {
flex-direction: row-reverse;

.nut-radio__label {
margin-right: $radio-label-margin-left;
margin-left: 0;
Expand All @@ -43,11 +49,13 @@
color: $radio-label-font-color;
box-sizing: border-box;
border: 1px solid #f6f7f9;

&--active {
background: transparent;
color: $radio-label-font-active-color;
border: 1px solid $radio-label-button-border-color;
position: relative;

&::after {
position: absolute;
top: 0;
Expand All @@ -61,6 +69,7 @@
content: '';
}
}

&--disabled {
color: $radio-label-disable-color;
border: none;
Expand All @@ -72,6 +81,7 @@
margin-left: $radio-label-margin-left;
font-size: $radio-label-font-size;
color: $radio-label-font-color;

&--disabled {
color: $radio-label-disable-color;
}
Expand All @@ -82,9 +92,11 @@
transition-duration: 0.3s;
transition-property: color, border-color, background-color;
}

&__icon--unchecked {
color: $radio-icon-disable-color;
}

&__icon--disable {
color: $radio-icon-disable-color2;
}
Expand Down
18 changes: 5 additions & 13 deletions src/packages/__VUE/radio/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export default create({
: 'nut-radio__icon--disable';
});
const position = computed(() => {
return parent.position;
});
const renderIcon = () => {
const { iconSize } = props;
const iconNodeMap = {
Expand Down Expand Up @@ -89,22 +85,18 @@ export default create({
parent.updateValue(props.label);
};
let reverseState = position.value === 'left';
const reverseState = computed(() => parent.position.value === 'left');
return () => {
return h(
'view',
{
class: `${componentName} ${componentName}--${props.shape} ${reverseState ? `${componentName}--reverse` : ''}`,
class: `${componentName} ${componentName}--${props.shape} ${
reverseState.value ? `${componentName}--reverse` : ''
}`,
onClick: handleClick
},
[
props.shape == 'button'
? renderButton()
: reverseState
? [renderLabel(), renderIcon()]
: [renderIcon(), renderLabel()]
]
[props.shape == 'button' ? renderButton() : [renderIcon(), renderLabel()]]
);
};
}
Expand Down
19 changes: 6 additions & 13 deletions src/packages/__VUE/radio/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export default create({
: 'nut-radio__icon--disable';
});
const position = computed(() => {
return parent.position;
});
const renderIcon = () => {
const { iconSize } = props;
const iconNodeMap = {
Expand All @@ -71,6 +67,7 @@ export default create({
slots.default?.()
);
};
const renderButton = () => {
return h(
'view',
Expand All @@ -88,22 +85,18 @@ export default create({
parent.updateValue(props.label);
};
let reverseState = position.value === 'left';
const reverseState = computed(() => parent.position.value === 'left');
return () => {
return h(
'view',
{
class: `${componentName} ${componentName}--${props.shape} ${reverseState ? `${componentName}--reverse` : ''}`,
class: `${componentName} ${componentName}--${props.shape} ${
reverseState.value ? `${componentName}--reverse` : ''
}`,
onClick: handleClick
},
[
props.shape == 'button'
? renderButton()
: reverseState
? [renderLabel(), renderIcon()]
: [renderIcon(), renderLabel()]
]
[props.shape === 'button' ? renderButton() : [renderIcon(), renderLabel()]]
);
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/radiogroup/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default create({
provide('parent', {
label: readonly(computed(() => props.modelValue)),
position: props.textPosition,
position: readonly(computed(() => props.textPosition)),
updateValue
});
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/radiogroup/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default create({
provide('parent', {
label: readonly(computed(() => props.modelValue)),
position: props.textPosition,
position: readonly(computed(() => props.textPosition)),
updateValue
});
Expand Down

0 comments on commit 5f56359

Please sign in to comment.