Skip to content

Commit b8538d8

Browse files
authored
[graphiql] fix placeholder ⌘ K in doc explorer search input for non mac devices, replace by Ctrl K (#3751)
1 parent 1a561b3 commit b8538d8

File tree

10 files changed

+25
-23
lines changed

10 files changed

+25
-23
lines changed

.changeset/lemon-mirrors-accept.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'codemirror-graphql': patch
3+
'@graphiql/react': patch
4+
'cm6-graphql': patch
5+
'graphiql': patch
6+
---
7+
8+
replace deprecated `navigator.platform` with `navigator.userAgent`
9+
10+
fix placeholder `⌘ K` in doc explorer search input for non mac devices, replace by `Ctrl K`

packages/cm6-graphql/src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ export class Position implements IPosition {
3838
}
3939
}
4040

41-
const isMac = () => /mac/i.test(navigator.platform);
41+
const isMac = () => navigator.userAgent.includes('Mac');
4242
export const isMetaKeyPressed = (e: MouseEvent) =>
4343
isMac() ? e.metaKey : e.ctrlKey;

packages/codemirror-graphql/src/utils/jump-addon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function onKeyDown(cm: CodeMirror.Editor, event: KeyboardEvent) {
121121
}
122122

123123
const isMac =
124-
typeof navigator !== 'undefined' && navigator?.appVersion.includes('Mac');
124+
typeof navigator !== 'undefined' && navigator.userAgent.includes('Mac');
125125

126126
function isJumpModifier(key: string) {
127127
return key === (isMac ? 'Meta' : 'Control');

packages/graphiql-react/src/editor/common.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { KeyMap } from './types';
2+
import { isMacOs } from '../utility/is-macos';
23

34
export const DEFAULT_EDITOR_THEME = 'graphiql';
45
export const DEFAULT_KEY_MAP: KeyMap = 'sublime';
56

6-
let isMacOs = false;
7-
8-
if (typeof window === 'object') {
9-
isMacOs = window.navigator.platform.toLowerCase().indexOf('mac') === 0;
10-
}
11-
127
export const commonKeys = {
138
// Persistent search box in Query Editor
149
[isMacOs ? 'Cmd-F' : 'Ctrl-F']: 'findPersistent',

packages/graphiql-react/src/explorer/components/doc-explorer.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
&:not(:focus-within) [role='combobox'] {
4040
height: 24px;
41-
width: 4ch;
41+
width: 5ch;
4242
}
4343

4444
& [role='combobox']:focus {

packages/graphiql-react/src/explorer/components/search.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { useExplorerContext } from '../context';
2424

2525
import './search.css';
2626
import { renderType } from './utils';
27+
import { isMacOs } from '../../utility/is-macos';
2728

2829
export function Search() {
2930
const { explorerNavStack, push } = useExplorerContext({
@@ -103,7 +104,7 @@ export function Search() {
103104
onFocus={handleFocus}
104105
onBlur={handleFocus}
105106
onChange={event => setSearchValue(event.target.value)}
106-
placeholder="⌘ K"
107+
placeholder={`${isMacOs ? '⌘' : 'Ctrl'} K`}
107108
ref={inputRef}
108109
value={searchValue}
109110
data-cy="doc-explorer-input"

packages/graphiql-react/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export {
7171
} from './storage';
7272
export { useTheme } from './theme';
7373
export { useDragResize } from './utility/resize';
74+
export { isMacOs } from './utility/is-macos';
7475

7576
export * from './icons';
7677
export * from './ui';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const isMacOs =
2+
typeof navigator !== 'undefined' && navigator.userAgent.includes('Mac');

packages/graphiql/src/components/GraphiQL.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
UseVariableEditorArgs,
6161
VariableEditor,
6262
WriteableEditorProps,
63+
isMacOs,
6364
} from '@graphiql/react';
6465

6566
const majorVersion = parseInt(React.version.slice(0, 2), 10);
@@ -915,11 +916,7 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
915916
);
916917
}
917918

918-
const modifier =
919-
typeof window !== 'undefined' &&
920-
window.navigator.platform.toLowerCase().indexOf('mac') === 0
921-
? 'Cmd'
922-
: 'Ctrl';
919+
const modifier = isMacOs ? '⌘' : 'Ctrl';
923920

924921
const SHORT_KEYS = Object.entries({
925922
'Search in editor': [modifier, 'F'],

packages/graphiql/test/beforeDevServer.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ const path = require('node:path');
1010
// eslint-disable-next-line import-x/no-extraneous-dependencies
1111
const { createHandler } = require('graphql-http/lib/use/express');
1212
const schema = require('./schema');
13-
const badSchema = require('../cypress/fixtures/bad-schema.json');
13+
const { customExecute } = require('./execute');
1414

1515
module.exports = function beforeDevServer(app, _server, _compiler) {
1616
// GraphQL Server
17-
app.post('/graphql', createHandler({ schema }));
18-
app.get('/graphql', createHandler({ schema }));
19-
20-
app.post('/bad/graphql', (_req, res, next) => {
21-
res.json({ data: badSchema });
22-
next();
23-
});
17+
const handler = createHandler({ schema, execute: customExecute });
18+
app.post('/graphql', handler);
19+
app.get('/graphql', handler);
2420

2521
app.use('/images', express.static(path.join(__dirname, 'images')));
2622

0 commit comments

Comments
 (0)