Skip to content

Commit 5dcfeb6

Browse files
authored
Display ctrl key in search bar for non-mac browsers (#5737)
* Add browser platform detection script (mac/win) * Hide platform specific content with css * Display ctrl + k in search bar on non-mac platforms * Update the platform detection comment
1 parent adb0d85 commit 5dcfeb6

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

beta/src/components/Search.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ function Hit({hit, children}: any) {
3030
);
3131
}
3232

33-
function Kbd(props: {children?: React.ReactNode}) {
33+
function Kbd(props: {children?: React.ReactNode; wide?: boolean}) {
34+
const {wide, ...rest} = props;
35+
const width = wide ? 'w-10' : 'w-5';
36+
3437
return (
3538
<kbd
36-
className="h-5 w-5 border border-transparent mr-1 bg-wash dark:bg-wash-dark text-gray-30 align-middle p-0 inline-flex justify-center items-center text-xs text-center rounded-md"
37-
{...props}
39+
className={`${width} h-5 border border-transparent mr-1 bg-wash dark:bg-wash-dark text-gray-30 align-middle p-0 inline-flex justify-center items-center text-xs text-center rounded-md`}
40+
{...rest}
3841
/>
3942
);
4043
}
@@ -168,7 +171,10 @@ export function Search({
168171
<IconSearch className="mr-3 align-middle text-gray-30 shrink-0 group-betterhover:hover:text-gray-70" />
169172
Search
170173
<span className="ml-auto hidden sm:flex item-center mr-1">
171-
<Kbd></Kbd>
174+
<Kbd data-platform="mac"></Kbd>
175+
<Kbd data-platform="win" wide>
176+
Ctrl
177+
</Kbd>
172178
<Kbd>K</Kbd>
173179
</span>
174180
</button>

beta/src/pages/_document.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ const MyDocument = () => {
4949
setTheme(e.matches ? 'dark' : 'light');
5050
}
5151
});
52+
53+
// Detect whether the browser is Mac to display platform specific content
54+
// An example of such content can be the keyboard shortcut displayed in the search bar
55+
document.documentElement.classList.add(
56+
window.navigator.platform.includes('Mac')
57+
? "platform-mac"
58+
: "platform-win"
59+
);
5260
})();
5361
`,
5462
}}

beta/src/styles/index.css

+9
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@
9797
display: none;
9898
}
9999

100+
/* Hide all content that's relevant only to a specific platform */
101+
html.platform-mac [data-platform='win'] {
102+
display: none;
103+
}
104+
105+
html.platform-win [data-platform='mac'] {
106+
display: none;
107+
}
108+
100109
html,
101110
body {
102111
padding: 0;

0 commit comments

Comments
 (0)