ant-design/components/switch/demo/disabled.md

40 lines
574 B
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 1
2016-07-26 09:17:46 +08:00
title:
zh-CN: 不可用
en-US: Disabled
2016-03-31 09:40:55 +08:00
---
2015-07-13 16:51:56 +08:00
2016-07-26 09:17:46 +08:00
## zh-CN
2015-07-20 14:32:21 +08:00
Switch 失效状态。
2015-07-13 16:51:56 +08:00
2016-07-26 09:17:46 +08:00
## en-US
Disabled state of `Switch`.
```tsx
2022-05-23 14:37:16 +08:00
import { Button, Switch } from 'antd';
import React, { useState } from 'react';
2015-07-13 16:51:56 +08:00
const App: React.FC = () => {
const [disabled, setDisabled] = useState(true);
2018-06-27 15:55:04 +08:00
const toggle = () => {
setDisabled(!disabled);
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
return (
<>
<Switch disabled={disabled} defaultChecked />
<br />
<Button type="primary" onClick={toggle}>
Toggle disabled
</Button>
</>
);
};
2015-07-13 16:51:56 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```