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

Is there any way to give custom tooltip text to toolbar ? #213

Closed
IntelligaiaVivek opened this issue Jul 23, 2021 · 8 comments
Closed

Is there any way to give custom tooltip text to toolbar ? #213

IntelligaiaVivek opened this issue Jul 23, 2021 · 8 comments

Comments

@IntelligaiaVivek
Copy link

IntelligaiaVivek commented Jul 23, 2021

Can we give custom tooltip text to toolbar like we have buttonProps: { "aria-label": "Insert bold text", "titile": "Insert bold text" } for group but needed for
single command.

example:-
commands.bold
tooltip text "Insert bold text"

@jaywcjlove
Copy link
Member

@IntelligaiaVivek Welcome to submit PR, modify the tooltip

import React from "react";
import MDEditor, { commands } from "@uiw/react-md-editor";

export default function App() {
  const [value, setValue] = React.useState("**Hello world!!!**");
  return (
    <div className="container">
      <MDEditor
        value={value}
        commands={[
          {
            ...commands.bold,
            buttonProps: { title: "Test Title" }
          }
        ]}
        onChange={(val) => {
          setValue(val!);
        }}
      />
    </div>
  );
}

@jaywcjlove
Copy link
Member

https://codesandbox.io/s/react-md-editor-custom-toolbars-213-c4g5h

@IntelligaiaVivek

@IntelligaiaVivek
Copy link
Author

Thanks for this Wonderful 'react-md-editor' Awesome

@cmldk
Copy link

cmldk commented Feb 15, 2023

There is an issue with commands.link. I can not override the value as expected. It still returns default value [](url) . @jaywcjlove

{
   ...commands.link,
   value: '[Text Here](URL Here)',
}

@jaywcjlove
Copy link
Member

@cmldk please give your example

@cmldk
Copy link

cmldk commented Feb 17, 2023

This was my first example when I was commenting on this. I was trying to create custom markdown commands. @jaywcjlove

{
  { ...commands.bold, buttonProps: { title: `${translate('addBold')} (Ctrl/Cmd + B)` } },
  { ...commands.italic, buttonProps: { title: `${translate('addItalic')} (Ctrl/Cmd + I)` } },
  commands.divider,
  {
   ...commands.link,
   value: '[Text Here](URL Here)',
  },
}

After considering the problem, I found out why this happens. [](url) text (value) is also generated while executing the function. And this is my solution as shown below.

{
    ...commands.link,
    buttonProps: { title: `${translate('addLink')} (Ctrl/Cmd + L)` },
    execute: (state, api) => {
      const newSelectionRange = selectWord({ text: state.text, selection: state.selection });
      const state1 = api.setSelectionRange(newSelectionRange);
      let state2;
      let urlHereText = translate('urlHere');
      if (state1.selectedText) {
        // selection
        state2 = api.replaceSelection(`[${state1.selectedText}](${urlHereText})`);
      } else {
        // empty selection
        state2 = api.replaceSelection(`[${translate('textHere')}](${urlHereText})`);
      }
      api.setSelectionRange({
        start: state2.selection.end - urlHereText.length - 1,
        end: state2.selection.end - 1,
      });
    },
  },

Thanks

jaywcjlove added a commit that referenced this issue Feb 17, 2023
@jaywcjlove
Copy link
Member

@IntelligaiaVivek Upgrade v3.20.5

github-actions bot added a commit that referenced this issue Feb 17, 2023
@IntelligaiaVivek
Copy link
Author

Thanks @jaywcjlove for the updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants