Can the Accordion trigger text change depending on whether the parent item is open or not? #1515
-
Hey all, When the item is closed, I want to be able to provide a summary of the content: Then, when it's open, it would just look like: It looks like I can use a state variable to control which item is open, but is there an onClick I can use, or something else to broadcast when the element is clicked, so I can track it externally? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @hoggworks, You should be able to achieve what you are after by using the controlled API of |
Beta Was this translation helpful? Give feedback.
-
Thanks very much!
… On Jul 7, 2022, at 11:24 AM, Andy Hook ***@***.***> wrote:
Quick example for type="single" that I had in my pocket https://codesandbox.io/s/accordion-change-trigger-text-when-open-q0vc25?file=/App.js <https://codesandbox.io/s/accordion-change-trigger-text-when-open-q0vc25?file=/App.js>
—
Reply to this email directly, view it on GitHub <#1515 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACN2M72MS2VVW4PH5ZLQF5LVS3ZDLANCNFSM525HPS4Q>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
Hi @hoggworks,
You should be able to achieve what you are after by using the controlled API of
Accordion
(value
,onValueChange
).You then are the one providing the state, and can switch your text based on whether the current
value
is the one in each item (or contains, if you allow multiple opened at the same time).