fix copy to clipboard and tabs styles in Safari (#69)

This commit is contained in:
Dimitri POSTOLOV 2022-05-24 16:51:56 +02:00 committed by GitHub
parent 33fcbb71de
commit 7f2b8cf3f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 22 deletions

View file

@ -36,8 +36,8 @@ export default class MyDocument extends Document {
id="force-dark-mode"
dangerouslySetInnerHTML={{
__html: `
localStorage['chakra-ui-color-mode'] = 'dark';
document.documentElement.classList.add('dark');
localStorage['chakra-ui-color-mode'] = 'dark';
document.documentElement.classList.add('dark');
`,
}}
/>

View file

@ -41,6 +41,7 @@ Tabs.Trigger = forwardRef(
<Trigger
ref={forwardedRef as any}
className={clsx(
'!appearance-none', // unset button styles in Safari
`
radix-state-active:text-white
font-bold

View file

@ -6,33 +6,17 @@ export function useClipboard() {
return useCallback(
async (text: string): Promise<void> => {
const result = await navigator.permissions.query({
name: 'clipboard-write' as any,
});
if (result.state === 'denied') {
if (!navigator?.clipboard) {
notify('Access to clipboard rejected!', 'error');
return;
}
// TODO: toast throws when used in Modal and modal's Portal is document.body
const isV2 = window.location.pathname.startsWith('/v2');
try {
await navigator.clipboard.writeText(text);
if (!isV2) {
notify('Copied to clipboard!', 'info');
}
} catch (e) {
if (!isV2) {
notify('Failed to copy!', 'error');
}
notify('Copied to clipboard!', 'info');
} catch {
notify('Failed to copy!', 'error');
}
},
[notify]
);
}
// navigator.permissions.query({name: "clipboard-write"}).then(result => {
// if (result.state == "granted" || result.state == "prompt") {
// /* write to the clipboard now */
// }
// });