Skip to content

Commit

Permalink
fix(SegmentedControl): set global focus styles (#5140)
Browse files Browse the repository at this point in the history
* Revert "revert: set global focus styles (#5114)"

This reverts commit 9f37707.

* fix(SegmentedControl): add offset to globalFocusStyle

* test(SegmentedControl): add e2e focus tests

* test(vrt): update snapshots

* test(SegmentedControl): only test focus state on button and icon stories

* Revert "test(vrt): update snapshots"

This reverts commit 5736299.

* test(vrt): update snapshots

---------

Co-authored-by: francinelucca <francinelucca@users.noreply.github.com>
  • Loading branch information
francinelucca and francinelucca authored Oct 22, 2024
1 parent a8c7517 commit 73796d3
Show file tree
Hide file tree
Showing 58 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-paws-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

fix(SegmentedControl): set global focus styles
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.
34 changes: 34 additions & 0 deletions e2e/components/SegmentedControl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ test.describe('SegmentedControl', () => {

// Default state
expect(await page.screenshot()).toMatchSnapshot(`SegmentedControl.Default.${theme}.png`)

// Focus state
await page.keyboard.press('Tab')
expect(await page.screenshot()).toMatchSnapshot(`SegmentedControl.Default.${theme}.focus.png`)

// Middle Button Focus state
await page.keyboard.press('Tab')
await page.keyboard.press('Enter')
await page.keyboard.press('Shift+Tab')
expect(await page.screenshot()).toMatchSnapshot(`SegmentedControl.Default.${theme}.middle.selected.focus.png`)
})

test('axe @aat', async ({page}) => {
Expand Down Expand Up @@ -407,6 +417,18 @@ test.describe('SegmentedControl', () => {

// Default state
expect(await page.screenshot()).toMatchSnapshot(`SegmentedControl.Icon Only.${theme}.png`)

// Focus state
await page.keyboard.press('Tab')
expect(await page.screenshot()).toMatchSnapshot(`SegmentedControl.Icon Only.${theme}.focus.png`)

// Middle Button Focus state
await page.keyboard.press('Tab')
await page.keyboard.press('Enter')
await page.keyboard.press('Shift+Tab')
expect(await page.screenshot()).toMatchSnapshot(
`SegmentedControl.Icon Only.${theme}.middle.selected.focus.png`,
)
})

test('axe @aat', async ({page}) => {
Expand Down Expand Up @@ -445,6 +467,18 @@ test.describe('SegmentedControl', () => {

// Default state
expect(await page.screenshot()).toMatchSnapshot(`SegmentedControl.With Icons.${theme}.png`)

// Focus state
await page.keyboard.press('Tab')
expect(await page.screenshot()).toMatchSnapshot(`SegmentedControl.With Icons.${theme}.focus.png`)

// Middle Button Focus state
await page.keyboard.press('Tab')
await page.keyboard.press('Enter')
await page.keyboard.press('Shift+Tab')
expect(await page.screenshot()).toMatchSnapshot(
`SegmentedControl.With Icons.${theme}.middle.selected.focus.png`,
)
})

test('axe @aat', async ({page}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import sx, {merge} from '../sx'
import {getSegmentedControlButtonStyles, getSegmentedControlListItemStyles} from './getSegmentedControlStyles'
import {defaultSxProp} from '../utils/defaultSxProp'
import {isElement} from 'react-is'
import getGlobalFocusStyles from '../internal/utils/getGlobalFocusStyles'

export type SegmentedControlButtonProps = {
/** The visible label rendered in the button */
Expand All @@ -22,6 +23,7 @@ export type SegmentedControlButtonProps = {
ButtonHTMLAttributes<HTMLButtonElement | HTMLLIElement>

const SegmentedControlButtonStyled = styled.button`
${getGlobalFocusStyles('-1px')};
${sx};
`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {getSegmentedControlButtonStyles, getSegmentedControlListItemStyles} from
import Box from '../Box'
import {defaultSxProp} from '../utils/defaultSxProp'
import {isElement} from 'react-is'
import getGlobalFocusStyles from '../internal/utils/getGlobalFocusStyles'

export type SegmentedControlIconButtonProps = {
'aria-label': string
Expand All @@ -21,6 +22,7 @@ export type SegmentedControlIconButtonProps = {
ButtonHTMLAttributes<HTMLButtonElement | HTMLLIElement>

const SegmentedControlIconButtonStyled = styled.button`
${getGlobalFocusStyles('-1px')};
${sx};
`

Expand Down

0 comments on commit 73796d3

Please sign in to comment.