Skip to content

Commit b2611b6

Browse files
siddharthkpSiddharth Kshetrapalcolebemis
authored
Avatar: add alt and src (#1416)
* add alt and src + update tests * Improve copy for alt text Co-authored-by: Cole Bemis <colebemis@github.com> Co-authored-by: Siddharth Kshetrapal <sid@Siddharths-MacBook-Pro.local> Co-authored-by: Cole Bemis <colebemis@github.com>
1 parent f4e1de6 commit b2611b6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Avatar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ type StyledAvatarProps = {
88
size?: number
99
/** Sets the shape of the avatar to a square if true. If false, the avatar will be circular. */
1010
square?: boolean
11+
/** URL of the avatar image. */
12+
src: string
13+
/** Provide alt text when the Avatar is used without the user's name next to it. */
14+
alt?: string
1115
} & SystemCommonProps &
1216
SxProp
1317

src/__tests__/Avatar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ describe('Avatar', () => {
1616
})
1717

1818
it('should have no axe violations', async () => {
19-
const {container} = HTMLRender(<Avatar />)
19+
const {container} = HTMLRender(<Avatar src="primer.png" />)
2020
const results = await axe(container)
2121
expect(results).toHaveNoViolations()
2222
cleanup()
2323
})
2424

2525
it('renders small by default', () => {
2626
const size = 20
27-
const result = render(<Avatar alt="" />)
27+
const result = render(<Avatar src="primer.png" />)
2828
expect(result.props.width).toEqual(size)
2929
expect(result.props.height).toEqual(size)
3030
})
3131

3232
it('respects the size prop', () => {
33-
const result = render(<Avatar size={40} alt="github" />)
33+
const result = render(<Avatar size={40} src="primer.png" alt="github" />)
3434
expect(result.props.width).toEqual(40)
3535
expect(result.props.height).toEqual(40)
3636
})
@@ -40,6 +40,6 @@ describe('Avatar', () => {
4040
})
4141

4242
it('respects margin props', () => {
43-
expect(render(<Avatar m={2} alt="" />)).toHaveStyleRule('margin', px(theme.space[2]))
43+
expect(render(<Avatar m={2} src="primer.png" alt="" />)).toHaveStyleRule('margin', px(theme.space[2]))
4444
})
4545
})

0 commit comments

Comments
 (0)