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

[EuiMarkdownFormat] : Allow links to open in a new tab! #7919

Closed
adhishthite opened this issue Jul 26, 2024 · 11 comments · Fixed by #7985
Closed

[EuiMarkdownFormat] : Allow links to open in a new tab! #7919

adhishthite opened this issue Jul 26, 2024 · 11 comments · Fixed by #7985
Labels
feature request help wanted The EUI team is looking for community members to pick up and implement this issue

Comments

@adhishthite
Copy link

Is your feature request related to a problem? Please describe.
I'm always frustrated when links in the EuiMarkdownFormat open in the same page.

Describe the solution you'd like
We should at least have an option that will allow links to open in a new tab without referrers etc, so that the context and flow is not lost.

Describe alternatives you've considered
Tried using custom props, but did not work.

Desired timeline
This seems like a minor change. Should happen quick.

Additional context
Thanks!

@JasonStoltz
Copy link
Member

@adhishthite Did you have a specific use case from Kibana in mind?

@JasonStoltz
Copy link
Member

Are you looking for a mechanism to selectively pick which links open in a new tab, or a configuration to open all links in a new tab?

@adhishthite
Copy link
Author

adhishthite commented Jul 30, 2024 via email

@zebde
Copy link

zebde commented Jul 31, 2024

Hey @adhishthite I had the same requirement and used the MarkdownPlugin capability to add a quick bit of code to open links in a new tab if they were external to the current app.

I am sure it isn't perfect and a built-in prop would be useful, but hopefully this will get you by for the time being.

import { EuiLink, getDefaultEuiMarkdownProcessingPlugins } from "@elastic/eui";

// eslint-disable-next-line no-restricted-globals
const isExternalURL = (url) => new URL(url).origin !== location.origin;

const markdownProcessingPlugins = () => {
  const defaultPlugins = getDefaultEuiMarkdownProcessingPlugins();
  defaultPlugins[1][1].components.a = (props) => {
    const isExternal = isExternalURL(props.href);
    return (
      <EuiLink target={isExternal ? "_blank" : ""} href={props.href}>
        {props.children}
      </EuiLink>
    );
  };
  return defaultPlugins;
};

export default markdownProcessingPlugins;

@adhishthite
Copy link
Author

Thanks @zebde ! I will definitely look into this. Appreciate the help.

@cee-chen
Copy link
Member

cee-chen commented Aug 5, 2024

Thanks for the suggestion @zebde! I'm very glad that the extensibility of EuiMarkdownEditor is working as intended to allow consumers to expand on its functionality. One quick caution, I know that links in new tabs can be considered an accessibility issue, which is the only reason we might hesitate to incorporate this into EUI directly or allow it as a configuration.

@1Copenut or @alexwizp, any chance you can jump in here with a recommendation as our resident accessibility experts?

@JasonStoltz
Copy link
Member

JasonStoltz commented Aug 19, 2024

@adhishthite We discussed this synchronously as a team today. In this case, we think there is value in making this change -- it would be a small change and has the potential to enhance to the user experience.

From a priority and planning perspective -- we aren't going to prioritize this as we don't have a concrete user facing need at this time and there is a workaround available.

However, I am going to add a "help wanted" label and we would gladly accept a PR for this one.

If you do end up adding a workaround in code, definitely consider adding a reference to this issue (https://github.com/elastic/eui/issues/7919) so we can circle back to it if this enhancement is made.

@JasonStoltz JasonStoltz added the help wanted The EUI team is looking for community members to pick up and implement this issue label Aug 19, 2024
Copy link

👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.

@hsk11
Copy link
Contributor

hsk11 commented Aug 27, 2024

PR: #7985
Solves the Issue

@cee-chen
Copy link
Member

The API to use to accomplish rendering tabs with target="_blank" will be:

const { processingPlugins } = getDefaultEuiMarkdownPlugins({
  processingConfig: {
    linkProps: { target: '_blank' }, // Accepts any prop that EuiLink takes - for example, `color: 'danger'` or `disabled: true`
  },
});

<EuiMarkdownFormat processingPluginList={processingPlugins}>
  [Opens in new tab](https://elastic.co)
</EuiMarkdownFormat>

<EuiMarkdownEditor processingPluginList={processingPlugins} />

See https://eui.elastic.co/pr_7985/#/editors-syntax/markdown-plugins#configuring-the-default-plugins for a full list of default plugin configurations that will be supported next release.

@adhishthite
Copy link
Author

Great work @hsk11 ! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request help wanted The EUI team is looking for community members to pick up and implement this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants