Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(radio): 修复radio-group的textPosition属性没有响应式 #2572

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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