Skip to content

Commit

Permalink
fix(Checkbox): fix Checkbox readonly (#3077)
Browse files Browse the repository at this point in the history
* fix(Checkbox): fix Checkbox readonly

* chore: update snapshot (#3069)

* chore: update snapshot

* chore: fix ci

* chore: fix ci

* chore: fix

* perf(useMutationobserver): optimiza performance (#3049)

* refactor(usemutationobserver): optimiza performance

* chore(usemutationobserver): fix spell

* Update src/hooks/useMutationObserver.ts

* fix(checkbox): fix checkbox readonly can trigger

---------

Co-authored-by: Heising <heising@travelconnect.cn>
Co-authored-by: wū yāng <uyarnchen@gmail.com>
  • Loading branch information
3 people authored Sep 3, 2024
1 parent 6089140 commit be7f7e5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/common/Check.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const Check = forwardRef<HTMLLabelElement, CheckProps>((_props, ref) => {
[`${classPrefix}-is-indeterminate`]: indeterminate,
});

const isDisabled = disabled || readonly;

const input = (
<input
readOnly={readonly}
Expand All @@ -82,7 +84,10 @@ const Check = forwardRef<HTMLLabelElement, CheckProps>((_props, ref) => {
setInternalChecked(!e.currentTarget.checked, { e });
}
}}
onChange={(e) => setInternalChecked(e.currentTarget.checked, { e })}
onChange={(e) => {
if (isDisabled) return;
setInternalChecked(e.currentTarget.checked, { e });
}}
/>
);
// Checkbox/ Radio 内容为空则不再渲染 span,不存在 0:Number 的情况
Expand All @@ -96,6 +101,7 @@ const Check = forwardRef<HTMLLabelElement, CheckProps>((_props, ref) => {
};

const onInnerClick = (e: MouseEvent<HTMLLabelElement>) => {
if (isDisabled) return;
onClick?.({ e });
};

Expand Down

0 comments on commit be7f7e5

Please sign in to comment.