Skip to content

Commit d5d98b0

Browse files
refactor: address pr comments.
1 parent 6e7373e commit d5d98b0

4 files changed

Lines changed: 28 additions & 22 deletions

File tree

playwright/workspace-tabs.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ test('removing active tab selects deterministic adjacent tab', async ({ page })
4242
await page.getByRole('button', { name: 'Open tab module-2.tsx' }).click()
4343
await expect(
4444
page.getByRole('button', { name: 'Open tab module-2.tsx' }),
45-
).toHaveAttribute('aria-pressed', 'true')
45+
).toHaveAttribute('aria-current', 'true')
4646

4747
await page.getByRole('button', { name: 'Remove tab module-2.tsx' }).click()
4848
await confirmRemoveDialog(page)
4949

5050
await expect(page.getByRole('button', { name: 'Open tab module-2.tsx' })).toHaveCount(0)
5151
await expect(
5252
page.getByRole('button', { name: 'Open tab module-3.tsx' }),
53-
).toHaveAttribute('aria-pressed', 'true')
53+
).toHaveAttribute('aria-current', 'true')
5454
})
5555

5656
test('removing non-active tab does not change active tab', async ({ page }) => {
@@ -63,15 +63,15 @@ test('removing non-active tab does not change active tab', async ({ page }) => {
6363
await page.getByRole('button', { name: 'Open tab module-3.tsx' }).click()
6464
await expect(
6565
page.getByRole('button', { name: 'Open tab module-3.tsx' }),
66-
).toHaveAttribute('aria-pressed', 'true')
66+
).toHaveAttribute('aria-current', 'true')
6767

6868
await page.getByRole('button', { name: 'Remove tab module-2.tsx' }).click()
6969
await confirmRemoveDialog(page)
7070

7171
await expect(page.getByRole('button', { name: 'Open tab module-2.tsx' })).toHaveCount(0)
7272
await expect(
7373
page.getByRole('button', { name: 'Open tab module-3.tsx' }),
74-
).toHaveAttribute('aria-pressed', 'true')
74+
).toHaveAttribute('aria-current', 'true')
7575
})
7676

7777
test('renaming module tab keeps name and path synchronized', async ({ page }) => {
@@ -123,7 +123,7 @@ test('active tab remains source of truth for visible editor panel', async ({ pag
123123

124124
await page.getByRole('button', { name: 'Open tab app.css' }).click()
125125
await expect(page.getByRole('button', { name: 'Open tab app.css' })).toHaveAttribute(
126-
'aria-pressed',
126+
'aria-current',
127127
'true',
128128
)
129129
await expect(stylesPanel).not.toHaveAttribute('hidden', '')
@@ -132,15 +132,15 @@ test('active tab remains source of truth for visible editor panel', async ({ pag
132132
await page.getByRole('button', { name: 'Open tab module-2.tsx' }).click()
133133
await expect(
134134
page.getByRole('button', { name: 'Open tab module-2.tsx' }),
135-
).toHaveAttribute('aria-pressed', 'true')
135+
).toHaveAttribute('aria-current', 'true')
136136
await expect(componentPanel).not.toHaveAttribute('hidden', '')
137137
await expect(stylesPanel).toHaveAttribute('hidden', '')
138138

139139
await page.locator('#collapse-component').click()
140140
await page.getByRole('button', { name: 'Open tab app.css' }).click()
141141

142142
await expect(page.getByRole('button', { name: 'Open tab app.css' })).toHaveAttribute(
143-
'aria-pressed',
143+
'aria-current',
144144
'true',
145145
)
146146
await expect(stylesPanel).not.toHaveAttribute('hidden', '')
@@ -156,14 +156,14 @@ test('startup restores last active workspace tab after reload', async ({ page })
156156
await page.getByRole('button', { name: 'Open tab module-2.tsx' }).click()
157157
await expect(
158158
page.getByRole('button', { name: 'Open tab module-2.tsx' }),
159-
).toHaveAttribute('aria-pressed', 'true')
159+
).toHaveAttribute('aria-current', 'true')
160160

161161
await page.reload()
162162
await waitForInitialRender(page)
163163

164164
await expect(
165165
page.getByRole('button', { name: 'Open tab module-2.tsx' }),
166-
).toHaveAttribute('aria-pressed', 'true')
166+
).toHaveAttribute('aria-current', 'true')
167167
await expect(page.locator('#editor-panel-component')).not.toHaveAttribute('hidden', '')
168168
await expect(page.locator('#editor-panel-styles')).toHaveAttribute('hidden', '')
169169
})
@@ -175,7 +175,7 @@ test('add menu can create styles tab while component tab is active', async ({ pa
175175
await addWorkspaceTab(page, { kind: 'styles' })
176176

177177
await expect(page.getByRole('button', { name: 'Open tab module.css' })).toHaveAttribute(
178-
'aria-pressed',
178+
'aria-current',
179179
'true',
180180
)
181181
await expect(page.locator('#editor-panel-styles')).not.toHaveAttribute('hidden', '')

src/app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,11 @@ const renderWorkspaceTabs = () => {
17121712
fileNameNode.textContent = tabDisplay.fileName || tab.name
17131713
selectButton.append(fileNameNode)
17141714

1715-
selectButton.setAttribute('aria-pressed', isActive ? 'true' : 'false')
1715+
if (isActive) {
1716+
selectButton.setAttribute('aria-current', 'true')
1717+
} else {
1718+
selectButton.removeAttribute('aria-current')
1719+
}
17161720
selectButton.setAttribute('aria-label', `Open tab ${tab.name}`)
17171721
selectButton.addEventListener('click', event => {
17181722
event.stopPropagation()

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ <h2 id="preview-header">Preview</h2>
602602
<div class="controls">
603603
<label class="color-control" for="preview-bg-color">
604604
<span class="preview-bg-label">Background</span>
605-
<input id="preview-bg-color" type="color" value="#ffffff" />
605+
<input id="preview-bg-color" type="color" value="#12141c" />
606606
</label>
607607
<button
608608
class="panel-collapse-toggle"

src/modules/preview-background.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const toHexChannel = value => value.toString(16).padStart(2, '0')
55

66
const normalizeColorToHex = colorValue => {
77
if (typeof colorValue !== 'string' || colorValue.length === 0) {
8-
return defaultLightPreviewBackgroundColor
8+
return ''
99
}
1010

1111
if (/^#[\da-f]{6}$/i.test(colorValue)) {
@@ -24,12 +24,12 @@ const normalizeColorToHex = colorValue => {
2424

2525
const channels = colorValue.match(/\d+/g)
2626
if (!channels || channels.length < 3) {
27-
return defaultLightPreviewBackgroundColor
27+
return ''
2828
}
2929

3030
const [red, green, blue] = channels.slice(0, 3).map(value => Number.parseInt(value, 10))
3131
if ([red, green, blue].some(value => Number.isNaN(value))) {
32-
return defaultLightPreviewBackgroundColor
32+
return ''
3333
}
3434

3535
return `#${toHexChannel(red)}${toHexChannel(green)}${toHexChannel(blue)}`
@@ -44,18 +44,20 @@ export const createPreviewBackgroundController = ({
4444
let previewBackgroundCustomized = false
4545

4646
const resolveDefaultPreviewBackgroundColor = () => {
47+
const themeDefaultPreviewBackgroundColor =
48+
document.documentElement.dataset.theme === 'light'
49+
? defaultLightPreviewBackgroundColor
50+
: defaultDarkPreviewBackgroundColor
51+
4752
if (typeof getDefaultPreviewBackgroundColor === 'function') {
4853
const configuredColor = getDefaultPreviewBackgroundColor()
49-
if (typeof configuredColor === 'string' && configuredColor.length > 0) {
50-
return normalizeColorToHex(configuredColor)
54+
const normalizedConfiguredColor = normalizeColorToHex(configuredColor)
55+
if (normalizedConfiguredColor) {
56+
return normalizedConfiguredColor
5157
}
5258
}
5359

54-
if (document.documentElement.dataset.theme === 'light') {
55-
return defaultLightPreviewBackgroundColor
56-
}
57-
58-
return defaultDarkPreviewBackgroundColor
60+
return themeDefaultPreviewBackgroundColor
5961
}
6062

6163
const applyPreviewBackgroundColor = color => {

0 commit comments

Comments
 (0)