Skip to content

Commit

Permalink
fix(Icon): ensure icon name is rendered as data-testid (#4304)
Browse files Browse the repository at this point in the history
Also, it corrects icon size of icon when given like this `icon={<Bell
/>}` to e.g. a button.
  • Loading branch information
tujoworker authored Nov 20, 2024
1 parent c585491 commit 235b823
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ describe('FormStatus component', () => {
).toContain('max-width: 30rem;')
})

it('should have correct icon label', () => {
render(<Input status="Error message" status_state="error" />)
expect(
document.querySelector('[role="presentation"]')
).toHaveAttribute('data-testid', 'ErrorIcon icon')
expect(
document.querySelector('.dnb-form-status__text')
).toHaveTextContent('Error message')
})

it('should re-calculate max-width', () => {
const { rerender } = render(
<Input style={{ width: '10rem' }} status="status message" />
Expand Down
3 changes: 3 additions & 0 deletions packages/dnb-eufemia/src/components/icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export default function Icon(localProps: IconAllProps) {
}

export function getIconNameFromComponent(icon: IconProps['icon']): string {
if (React.isValidElement(icon) && icon?.type) {
icon = icon?.type as IconType
}
const name = typeof icon === 'function' ? icon.name : String(icon)
if (/^data:image\//.test(name)) {
return null
Expand Down

0 comments on commit 235b823

Please sign in to comment.