Skip to content

Commit

Permalink
Fix tooltip not working literally anywhere except main window
Browse files Browse the repository at this point in the history
* eslint & co. do not err when accidentially adding data atributes to React components
* somehow buttons are not instances of HTML elements
  • Loading branch information
hummingly committed Apr 4, 2023
1 parent 13fdaf3 commit 77e825a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/frontend/containers/Outliner/TagsPanel/TagMerge.tsx
Expand Up @@ -96,7 +96,7 @@ const renderTagOption = action((tag: ClientTag, index: number, selection: boolea
const hint = path.slice(0, Math.max(0, path.length - tag.name.length - 3));

return (
<GridOption key={id} rowIndex={index} selected={selection || undefined} data-tooltip={path}>
<GridOption key={id} rowIndex={index} selected={selection || undefined} tooltip={path}>
<GridOptionCell id={id} colIndex={1}>
<span
className="combobox-popup-option-icon"
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/containers/Settings/Appearance.tsx
Expand Up @@ -144,13 +144,13 @@ const CustomThemePicker = () => {
icon={IconSet.FOLDER_CLOSE}
text="Add..."
onClick={() => shell.openExternal(themeDir)}
data-tooltip="Open the directory containing the theme files"
tooltip="Open the directory containing the theme files"
/>
<Button
icon={IconSet.RELOAD}
text="Refresh"
onClick={refresh}
data-tooltip="Reload the list of themes and current theme"
tooltip="Reload the list of themes and current theme"
/>
</div>
);
Expand Down
10 changes: 9 additions & 1 deletion widgets/Button/index.tsx
Expand Up @@ -9,6 +9,7 @@ type ButtonProps = {
styling?: 'minimal' | 'outlined' | 'filled';
disabled?: boolean;
type?: 'button' | 'submit' | 'reset';
tooltip?: string;
};

const Button = ({
Expand All @@ -18,9 +19,16 @@ const Button = ({
styling = 'minimal',
disabled,
type = 'button',
tooltip,
}: ButtonProps) => {
return (
<button className={`btn-${styling}`} onClick={onClick} disabled={disabled} type={type}>
<button
className={`btn-${styling}`}
onClick={onClick}
disabled={disabled}
type={type}
data-tooltip={tooltip}
>
{icon}
{text}
</button>
Expand Down
5 changes: 3 additions & 2 deletions widgets/Combobox/GridCombobox.tsx
Expand Up @@ -326,12 +326,13 @@ interface RowProps {
rowIndex: number;
selected?: boolean;
children: React.ReactElement<CellProps> | React.ReactElement<CellProps>[];
tooltip?: string;
}

export const GridOption = ({ rowIndex, selected, children, ...props }: RowProps) => {
export const GridOption = ({ rowIndex, selected, children, tooltip }: RowProps) => {
return (
<div
{...props}
data-tooltip={tooltip}
role="row"
aria-rowindex={rowIndex}
aria-selected={selected}
Expand Down
4 changes: 2 additions & 2 deletions widgets/popovers/Tooltip.tsx
Expand Up @@ -22,8 +22,8 @@ export const TooltipLayer = ({ document }: { document: Document }) => {
reference(virtualElement.current);

const handleShow = (e: MouseEvent | FocusEvent): HTMLElement | undefined => {
const target = e.target;
if (!(target instanceof HTMLElement) || !target.dataset['tooltip']) {
const target = e.target as any;
if (target === null || !("dataset" in target) || !(target.dataset as any)['tooltip']) {
return;
}
content.current = target.dataset['tooltip'];
Expand Down

0 comments on commit 77e825a

Please sign in to comment.