Skip to content

Commit

Permalink
fix(taxonomy tree): options remain selected when switching in single …
Browse files Browse the repository at this point in the history
…mode

This is a hack fix since the tree is already built on top of React anti-patterns, which cause this in the first place. In the future a full refactor is really required to sort this out at its roots.

By adding an unstable `key`, it forces the component to re-render on every render. Without this, React assumes nothing has changed and does not react to the `selectedKey` update.

For large trees with everything expanded, this could cause performance issues but should be okay in most cases.
  • Loading branch information
Jake Stanger committed Feb 14, 2024
1 parent 36753f1 commit c358b58
Showing 1 changed file with 1 addition and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ export function TaxonomyTree(
className={styles.taxonomyItemFocusZone}
>
<ChoiceGroup
key={new Date().getTime()}
options={options}
selectedKey={
props.selection && props.selection.getSelection()[0]?.id
Expand Down

0 comments on commit c358b58

Please sign in to comment.