Skip to content

Commit

Permalink
[Checkbox] fix set value checked before options pushed, while checkbo…
Browse files Browse the repository at this point in the history
…x UI is not checked (Tencent#2914)

* fix: useElementLazyRender default value

* fix(checkbox): set value before options change does not work

* fix: useElementLazyRender
  • Loading branch information
chaishi authored Nov 22, 2023
1 parent 3f3900f commit 168f103
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ export default defineComponent({
[data, label, storeKey],
() => {
if (!storeKey.value) return;
if (!tChecked.value && checkboxStore.value?.parentChecked?.includes(props.value)) {
tChecked.value = true;
}
subscribeParentData(props.checkAll ? 'CHECK_ALL' : value.value);
},
{ immediate: true },
Expand All @@ -182,7 +185,7 @@ export default defineComponent({
if (props.readonly) return;
const checked = !tChecked.value;
setInnerChecked(checked, { e });
if (checkboxGroupData?.value.handleCheckboxChange) {
if (checkboxGroupData?.value.onCheckedChange) {
checkboxGroupData.value.onCheckedChange({
checked,
checkAll: props.checkAll,
Expand Down
3 changes: 3 additions & 0 deletions src/checkbox/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type ObserverListenerParams = {
class CheckboxStore {
observerMap: ObserverMap = {};

parentChecked: CheckboxGroupValue;

parentExist: boolean;

init() {
Expand All @@ -45,6 +47,7 @@ class CheckboxStore {
updateChecked({
checked, isCheckAll, oldChecked, indeterminate,
}: UpdateCheckedData) {
this.parentChecked = checked;
const changedChecked = oldChecked ? getChangedChecked(checked, oldChecked) : checked;
const checkedParams: ObserverListenerParams = {
parentChecked: checked,
Expand Down

0 comments on commit 168f103

Please sign in to comment.