Skip to content

Commit 365f066

Browse files
V-halfaroCopilot
andauthored
RestCodeSamples: swap FormControl and Select to Primer Brand (#63651)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dd7e864 commit 365f066

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎src/rest/components/RestCodeSamples.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState, useEffect, useRef, FormEvent } from 'react'
2-
import { FormControl, IconButton, Select, SegmentedControl } from '@primer/react'
2+
import { IconButton, SegmentedControl } from '@primer/react'
3+
import { FormControl, Select } from '@primer/react-brand'
34
import { CheckIcon, CopyIcon, InfoIcon } from '@primer/octicons-react'
45
import { announce } from '@primer/live-region-element'
56
import Cookies from '@/frame/components/lib/cookies'
@@ -137,7 +138,7 @@ export function RestCodeSamples({ operation, slug, heading }: Props) {
137138
</h4>
138139
{!isSingleExample && (
139140
<div className="pb-5 pt-2">
140-
<FormControl id="example-type-picker">
141+
<FormControl>
141142
<FormControl.Label visuallyHidden>Select the example type</FormControl.Label>
142143
<Select onChange={handleExampleSelection}>
143144
{exampleSelectOptions.map((option) => (

‎src/rest/tests/rendering.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ describe('REST references docs', () => {
134134
expect(optionTexts).toEqual(['Example (text/plain)', 'Rendering markdown (text/x-markdown)'])
135135
})
136136

137+
test('example selectors have unique ids and matching labels', async () => {
138+
// Three secrets operations each have multiple request examples.
139+
const $ = await getDOM('/en/rest/actions/secrets')
140+
141+
const selects = $('select')
142+
expect(selects.length).toBeGreaterThanOrEqual(3)
143+
144+
const ids = selects.map((i, select) => $(select).attr('id')).get()
145+
expect(ids).toHaveLength(selects.length)
146+
expect(new Set(ids).size).toBe(ids.length)
147+
148+
for (const id of ids) {
149+
const label = $(`label[for="${id}"]`)
150+
expect(label.length).toBe(1)
151+
expect(label.text().trim()).toBe('Select the example type')
152+
}
153+
154+
expect($('#example-type-picker').length).toBe(0)
155+
})
156+
137157
// All five /rest/meta permissionless operations support every fine-grained token type,
138158
// so noFineGrainedAccess is false and the RestAuth null guard never fires.
139159
test('RestAuth component hides auth section for permissionless endpoints', async () => {

0 commit comments

Comments
 (0)