0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NextUIのAccordionを任意のタイミングで全て閉じる方法

Posted at

ドキュメントにも明記されておらず、小一時間悩んだので・・・

ドキュメント

結論

propsのselectedKeysを使います

stateを宣言して

import { Key } from '@react-types/shared';

const [selectedKeys, setSelectedKeys] = useState<Iterable<Key>>([]);

selectedKeysのpropsと、onSelectionChangeのイベントに設定します

<Accordion selectedKeys={selectedKeys} onSelectionChange={setSelectedKeys}>

そして、閉じたいタイミングで以下を呼べば全て閉じます

setSelectedKeys([])
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?