Skip to content

Commit 5ddd6e1

Browse files
WWW: Remove tabIndex from live code editor (#836)
1 parent a434c9b commit 5ddd6e1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- WWW site keyboard navigation improvement
1213
- `Menu` closes by default on `MenuItem` click
1314
- Provide `@types/styled-system` as a package dependency
1415
- `TextArea` only supports vertical resizing now

packages/www/src/MDX/Pre/CodeSandbox.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import { Icon, IconButton, IconNames, Tooltip } from '@looker/components'
2828
import { PrismTheme, Language } from 'prism-react-renderer'
29-
import React, { FC, ReactNode, useState } from 'react'
29+
import React, { FC, ReactNode, useState, useCallback } from 'react'
3030
import CopyToClipboard from 'react-copy-to-clipboard'
3131
import {
3232
LiveProvider,
@@ -66,6 +66,18 @@ const CodeSandbox = ({
6666
setShowEditor(!showEditor)
6767
}
6868

69+
const liveEditorRef = useCallback(
70+
(node: HTMLDivElement) => {
71+
if (showEditor && node) {
72+
const liveEditorInput = node.querySelector('textarea')
73+
if (liveEditorInput) {
74+
liveEditorInput.tabIndex = -1
75+
}
76+
}
77+
},
78+
[showEditor]
79+
)
80+
6981
return (
7082
<SandboxWrapper>
7183
<LiveProvider
@@ -98,7 +110,7 @@ const CodeSandbox = ({
98110
)}
99111
</LiveConsumer>
100112
</LivePreviewWrapper>
101-
<EditorWrapper>
113+
<EditorWrapper ref={liveEditorRef}>
102114
{showEditor && <LiveEditor />}
103115
<ActionLayout editorIsVisible={showEditor}>
104116
<ToggleCodeButton

0 commit comments

Comments
 (0)