Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-components): add wrapper to buttons to eliminate MUI tooltip error #2023

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-bags-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remirror/react-components': patch
---

Fixed MUI tooltip error for buttons
10 changes: 1 addition & 9 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,7 @@
"name": "@remirror/extension-yjs",
"limit": "115 KB",
"path": "packages/remirror__extension-yjs/dist/remirror-extension-yjs.js",
"ignore": [
"@remirror/pm",
"prosemirror-model",
"prosemirror-state",
"prosemirror-view",
"yjs",
"@remirror/core",
"@remirror/messages"
],
"ignore": ["@remirror/pm", "yjs", "@remirror/core", "@remirror/messages"],
"running": false,
"gzip": true
},
Expand Down
78 changes: 41 additions & 37 deletions packages/remirror__react-components/src/buttons/command-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ToggleButton, ToggleButtonProps, Tooltip } from '@mui/material';
import { Box, ToggleButton, ToggleButtonProps, Tooltip } from '@mui/material';
import React, { FC, MouseEvent, MouseEventHandler, ReactNode, useCallback } from 'react';
import { CoreIcon, isString } from '@remirror/core';

Expand Down Expand Up @@ -58,42 +58,46 @@ export const CommandButton: FC<CommandButtonProps> = ({

return (
<Tooltip title={`${tooltipText}${shortcutText}`}>
<ToggleButton
aria-label={labelText}
selected={active}
disabled={!enabled}
onMouseDown={handleMouseDown}
color='primary'
size='small'
sx={{
padding: '6px 12px',
'&.Mui-selected': {
backgroundColor: 'primary.main',
color: 'primary.contrastText',
},
'&.Mui-selected:hover': {
backgroundColor: 'primary.dark',
color: 'primary.contrastText',
},
'&:not(:first-of-type)': {
marginLeft: '-1px',
borderLeft: '1px solid transparent',
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
},
'&:not(:last-of-type)': {
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
},
}}
{...rest}
value={commandName}
onChange={handleChange}
>
<CommandButtonBadge icon={commandOptions.icon}>
<CommandButtonIcon icon={icon ?? fallbackIcon} />
</CommandButtonBadge>
</ToggleButton>
{/*
This Box<span> wrapper fixes an MUI tooltip error when the button is disabled.
*/}
<Box component='span' sx={{ '&:not(:first-of-type)': { marginLeft: '-1px' } }}>
<ToggleButton
aria-label={labelText}
selected={active}
disabled={!enabled}
onMouseDown={handleMouseDown}
color='primary'
size='small'
sx={{
padding: '6px 12px',
'&.Mui-selected': {
backgroundColor: 'primary.main',
color: 'primary.contrastText',
},
'&.Mui-selected:hover': {
backgroundColor: 'primary.dark',
color: 'primary.contrastText',
},
'&:not(:first-of-type)': {
borderLeft: '1px solid transparent',
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
},
'&:not(:last-of-type)': {
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
},
}}
{...rest}
value={commandName}
onChange={handleChange}
>
<CommandButtonBadge icon={commandOptions.icon}>
<CommandButtonIcon icon={icon ?? fallbackIcon} />
</CommandButtonBadge>
</ToggleButton>
</Box>
</Tooltip>
);
};
Loading