Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/avatar-inner-border.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Avatar: Move the border inside the image for a crisper edge
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions packages/react/src/Avatar/Avatar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@
line-height: 1;
vertical-align: middle;
border-radius: 50%;
/* stylelint-disable-next-line primer/box-shadow */
box-shadow: 0 0 0 1px var(--avatar-borderColor);

&:where([data-component='AvatarStack'] *) {
/* Preserve the outer edge for stack items that don't override it. */
/* stylelint-disable-next-line primer/box-shadow */
box-shadow: 0 0 0 var(--borderWidth-thin) var(--avatar-borderColor);
}

&:where(:not(:focus-visible, [data-component='AvatarStack'] *)) {
/* An inset shadow paints behind the image; an outline paints over it. */
outline: var(--borderWidth-thin) solid var(--avatar-borderColor);
outline-offset: calc(-1 * var(--borderWidth-thin));

@media (forced-colors: active) {
outline: none;
}
}

&:where([data-square]) {
/* stylelint-disable-next-line primer/borders */
Expand Down
15 changes: 14 additions & 1 deletion packages/react/src/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, expect, it} from 'vitest'
import {render} from '@testing-library/react'
import {page} from 'vitest/browser'
import {page, userEvent} from 'vitest/browser'
import Avatar from '../Avatar'
import {implementsClassName} from '../utils/testing'
import classes from './Avatar.module.css'
Expand All @@ -24,6 +24,19 @@ describe('Avatar', () => {
await expect.element(avatar).toHaveAttribute('height', size.toString())
})

it('preserves the keyboard focus outline', async () => {
render(<Avatar src="primer.png" alt="Mona" tabIndex={0} />)
const avatar = page.getByRole('img', {name: 'Mona'})
await expect.element(avatar).toHaveStyle('outline-offset: -1px')

await userEvent.tab()

await expect.element(avatar).toHaveFocus()
const {outlineOffset, outlineStyle} = getComputedStyle(avatar.element())
expect(outlineOffset).not.toBe('-1px')
expect(outlineStyle).not.toBe('none')
})

it('respects the size prop', async () => {
render(<Avatar size={40} src="primer.png" alt="github" data-testid="avatar" />)
const avatar = page.getByTestId('avatar')
Expand Down
Loading