Skip to content

Commit

Permalink
[EuiIcon] Minor syntax cleanup
Browse files Browse the repository at this point in the history
- remove `let: any` in favor of a conditional (still needs to be an obj spread, react DOM yells about the invalid property otherwise)

- remove `hideIconEmpty` and object in favor of simply using a prop
  • Loading branch information
cee-chen committed Feb 23, 2024
1 parent edb9a42 commit 6b2adc0
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,14 @@ export class EuiIconClass extends PureComponent<
this.props['aria-labelledby'] ||
this.props.title
);
const hideIconEmpty = isAriaHidden && { 'aria-hidden': true };

let titleId: any;

// If no aria-label or aria-labelledby is provided but there's a title, a titleId is generated
// The svg aria-labelledby attribute gets this titleId
// The svg title element gets this titleId as an id
if (
!this.props['aria-label'] &&
!this.props['aria-labelledby'] &&
title
) {
titleId = { titleId: generateId() };
}
const titleId =
!this.props['aria-label'] && !this.props['aria-labelledby'] && title
? { titleId: generateId() }
: undefined;

return (
<Svg
Expand All @@ -327,12 +321,12 @@ export class EuiIconClass extends PureComponent<
tabIndex={tabIndex}
role="img"
title={title}
{...titleId}
data-icon-type={iconTitle}
data-is-loaded={isLoaded || undefined}
data-is-loading={isLoading || undefined}
{...titleId}
{...rest}
{...hideIconEmpty}
aria-hidden={isAriaHidden || undefined}
/>
);
}
Expand Down

0 comments on commit 6b2adc0

Please sign in to comment.