소스 검색

fix: [Switch] Change the initial setting of the state in the constructor in the switch to prevent animations that do not meet expectations (#1501)

YyumeiZhang 2 년 전
부모
커밋
0ff9442a46
2개의 변경된 파일3개의 추가작업 그리고 4개의 파일을 삭제
  1. 2 3
      packages/semi-foundation/switch/foundation.ts
  2. 1 1
      packages/semi-ui/switch/index.tsx

+ 2 - 3
packages/semi-foundation/switch/foundation.ts

@@ -15,8 +15,7 @@ export default class SwitchFoundation<P = Record<string, any>, S = Record<string
     }
 
     init(): void {
-        const { defaultChecked, checked, disabled } = this.getProps();
-        this.setChecked(defaultChecked || checked);
+        const { disabled } = this.getProps();
         this.setDisabled(disabled);
     }
 
@@ -45,7 +44,7 @@ export default class SwitchFoundation<P = Record<string, any>, S = Record<string
             if (target.matches(':focus-visible')) {
                 this._adapter.setFocusVisible(true);
             }
-        } catch (error){
+        } catch (error) {
             warning(true, 'Warning: [Semi Switch] The current browser does not support the focus-visible');
         }
     }

+ 1 - 1
packages/semi-ui/switch/index.tsx

@@ -73,7 +73,7 @@ class Switch extends BaseComponent<SwitchProps, SwitchState> {
     constructor(props: SwitchProps) {
         super(props);
         this.state = {
-            nativeControlChecked: false,
+            nativeControlChecked: props.defaultChecked || props.checked,
             nativeControlDisabled: false,
             focusVisible: false
         };