fix(ui): prevent literal "undefined" class name in useDefinition
When no className prop was passed to a component using useDefinition,
the hook would add a literal "undefined" string as a CSS class. This
happened because clsx treats object keys as class names, and
`{ [undefined]: true }` creates an "undefined" key.
Fixed by using conditional expressions instead of object syntax,
which clsx correctly ignores when falsy.
Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/ui': patch
|
||||
---
|
||||
|
||||
Fixed `useDefinition` hook adding literal "undefined" class name when no className prop was passed.
|
||||
@@ -103,10 +103,8 @@ export function useDefinition<
|
||||
classes[name] = clsx(
|
||||
cssKey as string,
|
||||
definition.styles[cssKey as keyof typeof definition.styles],
|
||||
{
|
||||
[utilityClasses]: utilityTarget === name,
|
||||
[ownPropsResolved.className]: classNameTarget === name,
|
||||
},
|
||||
utilityTarget === name && utilityClasses,
|
||||
classNameTarget === name && ownPropsResolved.className,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user