Open brunnerh opened 2 years ago
Previous issues: #368, #1493
The workaround is to wrap dynamic Tabs
in a #key
block (#438, https://github.com/carbon-design-system/carbon-components-svelte/discussions/1494#discussioncomment-3717572).
The "Svelte way" would be to avoid composition/context and use consumer-provided keys to track the tabs (#435).
@metonym
Using #key
is not ideal if the tabs contain a lot/complex content.
A solution using keys should not be too complicated, it could also use slot props like the DataTable
.
Are there any plans to revive the keyed approach?
Tabs/contents are never removed from the
Tabs
context and DOM order is not considered when determining the index, so if a tab is removed and added back in, it will have a higher/different index than before.E.g.
REPL
After toggling the boolean
showTab1
off and on the index of the first tab will have gone from0
to3
. This could cause issues when trying to select a specific tab or trying to identify which tab is selected.A possible fix might be to:
onDestroy
.focus()
the active tab via a relative DOM query).0
).(A different selection method based on explicit keys/IDs would also be helpful. Though this would not prevent the potential confusion caused by this issue.)