How to make Link fit Component that its inside of it?











up vote
0
down vote

favorite












What I have:



<div className="flexBox">
<h4>Rampa de Cores</h4>
<Link to={"/new"} className="link">
<CustomButton label="Adicionar" className={"addButton"}/>
</Link>
</div>


And the <CustomButton /> returns



<div>
<button className={this.props.className}>{this.props.label}</button>
</div>


The Problem:



buttonImage



All the area that i marked with a red square is clickable and triggers the <Link /> but I need to make it fit the button area only.



What I tried:



I looked for how to make a div fit it's content, in .link I have



.link {
display: inline-block;
}


but didn't work.



What i need:




  1. How to make <Link /> fit it's content?

  2. Or make a better way of triggering <Link /> using the button.










share|improve this question






















  • Buttons are not permitted as children of links.
    – Paulie_D
    Nov 19 at 11:45










  • You could try onClick with the button.
    – MrMaavin
    Nov 19 at 11:46










  • Just replace the link with an onClick in the button. React Router provides props which will let you "push" to a new url
    – Charlie
    Nov 19 at 11:49















up vote
0
down vote

favorite












What I have:



<div className="flexBox">
<h4>Rampa de Cores</h4>
<Link to={"/new"} className="link">
<CustomButton label="Adicionar" className={"addButton"}/>
</Link>
</div>


And the <CustomButton /> returns



<div>
<button className={this.props.className}>{this.props.label}</button>
</div>


The Problem:



buttonImage



All the area that i marked with a red square is clickable and triggers the <Link /> but I need to make it fit the button area only.



What I tried:



I looked for how to make a div fit it's content, in .link I have



.link {
display: inline-block;
}


but didn't work.



What i need:




  1. How to make <Link /> fit it's content?

  2. Or make a better way of triggering <Link /> using the button.










share|improve this question






















  • Buttons are not permitted as children of links.
    – Paulie_D
    Nov 19 at 11:45










  • You could try onClick with the button.
    – MrMaavin
    Nov 19 at 11:46










  • Just replace the link with an onClick in the button. React Router provides props which will let you "push" to a new url
    – Charlie
    Nov 19 at 11:49













up vote
0
down vote

favorite









up vote
0
down vote

favorite











What I have:



<div className="flexBox">
<h4>Rampa de Cores</h4>
<Link to={"/new"} className="link">
<CustomButton label="Adicionar" className={"addButton"}/>
</Link>
</div>


And the <CustomButton /> returns



<div>
<button className={this.props.className}>{this.props.label}</button>
</div>


The Problem:



buttonImage



All the area that i marked with a red square is clickable and triggers the <Link /> but I need to make it fit the button area only.



What I tried:



I looked for how to make a div fit it's content, in .link I have



.link {
display: inline-block;
}


but didn't work.



What i need:




  1. How to make <Link /> fit it's content?

  2. Or make a better way of triggering <Link /> using the button.










share|improve this question













What I have:



<div className="flexBox">
<h4>Rampa de Cores</h4>
<Link to={"/new"} className="link">
<CustomButton label="Adicionar" className={"addButton"}/>
</Link>
</div>


And the <CustomButton /> returns



<div>
<button className={this.props.className}>{this.props.label}</button>
</div>


The Problem:



buttonImage



All the area that i marked with a red square is clickable and triggers the <Link /> but I need to make it fit the button area only.



What I tried:



I looked for how to make a div fit it's content, in .link I have



.link {
display: inline-block;
}


but didn't work.



What i need:




  1. How to make <Link /> fit it's content?

  2. Or make a better way of triggering <Link /> using the button.







javascript css reactjs react-router






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 11:43









Vencovsky

386




386












  • Buttons are not permitted as children of links.
    – Paulie_D
    Nov 19 at 11:45










  • You could try onClick with the button.
    – MrMaavin
    Nov 19 at 11:46










  • Just replace the link with an onClick in the button. React Router provides props which will let you "push" to a new url
    – Charlie
    Nov 19 at 11:49


















  • Buttons are not permitted as children of links.
    – Paulie_D
    Nov 19 at 11:45










  • You could try onClick with the button.
    – MrMaavin
    Nov 19 at 11:46










  • Just replace the link with an onClick in the button. React Router provides props which will let you "push" to a new url
    – Charlie
    Nov 19 at 11:49
















Buttons are not permitted as children of links.
– Paulie_D
Nov 19 at 11:45




Buttons are not permitted as children of links.
– Paulie_D
Nov 19 at 11:45












You could try onClick with the button.
– MrMaavin
Nov 19 at 11:46




You could try onClick with the button.
– MrMaavin
Nov 19 at 11:46












Just replace the link with an onClick in the button. React Router provides props which will let you "push" to a new url
– Charlie
Nov 19 at 11:49




Just replace the link with an onClick in the button. React Router provides props which will let you "push" to a new url
– Charlie
Nov 19 at 11:49












3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










React Router provides a history prop to components.



You can replace your link and include an onClick in the button.



<div className="flexBox">
<h4>Rampa de Cores</h4>
<CustomButton
onClick={() => this.props.history.push('/new')}
label="Adicionar"
className={"addButton"}
/>
</div>





share|improve this answer




























    up vote
    1
    down vote













    You should not use button as a child of Link. Instead, you may use button and trigger a state change or redirection when the button is clicked. If the new route is declared with react-router-dom's Route, you may just use the following code:



    down vote
    favorite
    What I have:



     <div className="flexBox">
    <h4>Rampa de Cores</h4>
    <Link to={"/new"} className="link">
    <CustomButton label="Adicionar" className={"addButton"}
    onButtonClick={()=>this.props.history.push('/new')}/>
    </Link>
    </div>
    <button
    onClick={this.props.onButtonClick}
    >{this.props.label}</button>


    If your current component is not defined with Route, you must use withRouter from react-router-dom to get access to the history prop.






    share|improve this answer






























      up vote
      0
      down vote













      you can use below flex box styling or else simply make .link display:block; width:100%;



      .link{
      display:flex;
      flex-flow:row wrap;
      flex-basis:50%;
      min-width:50%;
      line-height:normal;
      }


      As far as height is concerned if the parent .flexbox display property is flex then height will be picked automatically.






      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373923%2fhow-to-make-link-fit-component-that-its-inside-of-it%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote



        accepted










        React Router provides a history prop to components.



        You can replace your link and include an onClick in the button.



        <div className="flexBox">
        <h4>Rampa de Cores</h4>
        <CustomButton
        onClick={() => this.props.history.push('/new')}
        label="Adicionar"
        className={"addButton"}
        />
        </div>





        share|improve this answer

























          up vote
          1
          down vote



          accepted










          React Router provides a history prop to components.



          You can replace your link and include an onClick in the button.



          <div className="flexBox">
          <h4>Rampa de Cores</h4>
          <CustomButton
          onClick={() => this.props.history.push('/new')}
          label="Adicionar"
          className={"addButton"}
          />
          </div>





          share|improve this answer























            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            React Router provides a history prop to components.



            You can replace your link and include an onClick in the button.



            <div className="flexBox">
            <h4>Rampa de Cores</h4>
            <CustomButton
            onClick={() => this.props.history.push('/new')}
            label="Adicionar"
            className={"addButton"}
            />
            </div>





            share|improve this answer












            React Router provides a history prop to components.



            You can replace your link and include an onClick in the button.



            <div className="flexBox">
            <h4>Rampa de Cores</h4>
            <CustomButton
            onClick={() => this.props.history.push('/new')}
            label="Adicionar"
            className={"addButton"}
            />
            </div>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 19 at 11:54









            Charlie

            1546




            1546
























                up vote
                1
                down vote













                You should not use button as a child of Link. Instead, you may use button and trigger a state change or redirection when the button is clicked. If the new route is declared with react-router-dom's Route, you may just use the following code:



                down vote
                favorite
                What I have:



                 <div className="flexBox">
                <h4>Rampa de Cores</h4>
                <Link to={"/new"} className="link">
                <CustomButton label="Adicionar" className={"addButton"}
                onButtonClick={()=>this.props.history.push('/new')}/>
                </Link>
                </div>
                <button
                onClick={this.props.onButtonClick}
                >{this.props.label}</button>


                If your current component is not defined with Route, you must use withRouter from react-router-dom to get access to the history prop.






                share|improve this answer



























                  up vote
                  1
                  down vote













                  You should not use button as a child of Link. Instead, you may use button and trigger a state change or redirection when the button is clicked. If the new route is declared with react-router-dom's Route, you may just use the following code:



                  down vote
                  favorite
                  What I have:



                   <div className="flexBox">
                  <h4>Rampa de Cores</h4>
                  <Link to={"/new"} className="link">
                  <CustomButton label="Adicionar" className={"addButton"}
                  onButtonClick={()=>this.props.history.push('/new')}/>
                  </Link>
                  </div>
                  <button
                  onClick={this.props.onButtonClick}
                  >{this.props.label}</button>


                  If your current component is not defined with Route, you must use withRouter from react-router-dom to get access to the history prop.






                  share|improve this answer

























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    You should not use button as a child of Link. Instead, you may use button and trigger a state change or redirection when the button is clicked. If the new route is declared with react-router-dom's Route, you may just use the following code:



                    down vote
                    favorite
                    What I have:



                     <div className="flexBox">
                    <h4>Rampa de Cores</h4>
                    <Link to={"/new"} className="link">
                    <CustomButton label="Adicionar" className={"addButton"}
                    onButtonClick={()=>this.props.history.push('/new')}/>
                    </Link>
                    </div>
                    <button
                    onClick={this.props.onButtonClick}
                    >{this.props.label}</button>


                    If your current component is not defined with Route, you must use withRouter from react-router-dom to get access to the history prop.






                    share|improve this answer














                    You should not use button as a child of Link. Instead, you may use button and trigger a state change or redirection when the button is clicked. If the new route is declared with react-router-dom's Route, you may just use the following code:



                    down vote
                    favorite
                    What I have:



                     <div className="flexBox">
                    <h4>Rampa de Cores</h4>
                    <Link to={"/new"} className="link">
                    <CustomButton label="Adicionar" className={"addButton"}
                    onButtonClick={()=>this.props.history.push('/new')}/>
                    </Link>
                    </div>
                    <button
                    onClick={this.props.onButtonClick}
                    >{this.props.label}</button>


                    If your current component is not defined with Route, you must use withRouter from react-router-dom to get access to the history prop.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 19 at 12:08

























                    answered Nov 19 at 11:59









                    Rohan Dhar

                    457210




                    457210






















                        up vote
                        0
                        down vote













                        you can use below flex box styling or else simply make .link display:block; width:100%;



                        .link{
                        display:flex;
                        flex-flow:row wrap;
                        flex-basis:50%;
                        min-width:50%;
                        line-height:normal;
                        }


                        As far as height is concerned if the parent .flexbox display property is flex then height will be picked automatically.






                        share|improve this answer

























                          up vote
                          0
                          down vote













                          you can use below flex box styling or else simply make .link display:block; width:100%;



                          .link{
                          display:flex;
                          flex-flow:row wrap;
                          flex-basis:50%;
                          min-width:50%;
                          line-height:normal;
                          }


                          As far as height is concerned if the parent .flexbox display property is flex then height will be picked automatically.






                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            you can use below flex box styling or else simply make .link display:block; width:100%;



                            .link{
                            display:flex;
                            flex-flow:row wrap;
                            flex-basis:50%;
                            min-width:50%;
                            line-height:normal;
                            }


                            As far as height is concerned if the parent .flexbox display property is flex then height will be picked automatically.






                            share|improve this answer












                            you can use below flex box styling or else simply make .link display:block; width:100%;



                            .link{
                            display:flex;
                            flex-flow:row wrap;
                            flex-basis:50%;
                            min-width:50%;
                            line-height:normal;
                            }


                            As far as height is concerned if the parent .flexbox display property is flex then height will be picked automatically.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 19 at 11:52









                            vssadineni

                            340110




                            340110






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373923%2fhow-to-make-link-fit-component-that-its-inside-of-it%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Wiesbaden

                                Marschland

                                Dieringhausen