(fix)修复star-select无法设置选中值的故障

This commit is contained in:
wangchangqi 2022-11-30 10:10:22 +08:00
parent 621f5e6981
commit 3141e18bad
1 changed files with 13 additions and 4 deletions

View File

@ -64,7 +64,11 @@ export class StarSelect extends StarBaseElement {
// }
protected firstUpdated(): void {
protected firstUpdated() {
this.initialOptionsSlot()
}
protected initialOptionsSlot() {
// 1. 为 radio 标签,或是有实现类 radio 标签行为的标签
// 如 <star-li type="radio"><star-card type="radio">
// 2. 不满足1的标签将被删除
@ -102,7 +106,7 @@ export class StarSelect extends StarBaseElement {
for (const [index, option] of this.optionsSlot.entries()) {
if (this.selected !== undefined) {
if (this.multiple === false) {
if (this.selected === option.value) {
if (String(this.selected) === option.value) {
this.label = option.label
option.checked = true
break
@ -132,7 +136,7 @@ export class StarSelect extends StarBaseElement {
/**
* star-radio-group change自定义事件
*/
_onselect(e: Event) {
protected _onselect(e: Event) {
const target = e.target as StarRadioGroup
if (this.selected !== target.selected) {
this.selected = target.getSelected()
@ -141,11 +145,16 @@ export class StarSelect extends StarBaseElement {
}
}
public setSelected(str: string | number) {
this.selected = String(str)
this.initialOptionsSlot()
}
/**
* <select-dialog> options
* <select-dialog> options
*/
_onclick(_: Event) {
protected _onclick(_: Event) {
const starAlertDialog = new StarSelectDialog({
title: this.title || '测试',
type: 'select',