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

How to open links in a new browser tab #15

Closed
cryptosteer opened this issue Aug 29, 2017 · 2 comments
Closed

How to open links in a new browser tab #15

cryptosteer opened this issue Aug 29, 2017 · 2 comments

Comments

@cryptosteer
Copy link

Hi, I am trying this, for example, in the UserLinks Commponent that renders "react-md/lib/Buttons"... I didn't find any way to set a target="_blank" or something like this.

@Vagr9K
Copy link
Owner

Vagr9K commented Aug 29, 2017

Hey there!

Use this code for UserLinks.jsx:

import React, { Component } from "react";
import Button from "react-md/lib/Buttons";
import "./UserLinks.scss";

class UserLinks extends Component {
  getLinkElements() {
    const { userLinks } = this.props.config;
    const { labeled } = this.props;
    return userLinks.map(link =>
      (<Button
        icon={!labeled}
        flat={labeled}
        secondary
        key={link.label}
        iconClassName={link.iconClassName}
        href={link.url}
        target="_blank"
      >
        {labeled ? link.label : ""}
      </Button>)
    );
  }
  render() {
    const { userLinks } = this.props.config;
    if (!userLinks) {
      return null;
    }
    return (
      <div className="user-links">
        {this.getLinkElements()}
      </div>
    );
  }
}

export default UserLinks;

The most important part is setting target="_blank" on a Button:

<Button
        icon={!labeled}
        flat={labeled}
        secondary
        key={link.label}
        iconClassName={link.iconClassName}
        href={link.url}
        target="_blank"
      >
        {labeled ? link.label : ""}
      </Button>

React-MD's Buttons automatically set their component to be a in case of any a related props being set (like href and target).

@cryptosteer
Copy link
Author

Awesome! Thank you!

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

2 participants