Item Templating with JSX

Hi Syncfusion Team,

Hi Syncfusion Team, I'm using the  DropDownButton component and I want to customize the Popup items. In your documents, I saw that Popup items can be customized by using the beforeItemRender event but only using the HTML element. I want to use the JSX element as replace. 


How to implement that.

Thanks.


13 Replies 1 reply marked as answer

YA YuvanShankar Arunagiri Syncfusion Team July 7, 2022 11:27 AM UTC

Hi Ton,


We have checked your reported query and prepared the sample based on your requirement. Please refer the below UG link and sample link. We have achieved your requirement by using Popup templating feature of the dropdown button.


UG link: https://ej2.syncfusion.com/react/documentation/drop-down-button/popup-items/#popup-templating


render() {

        return (<div className='control-pane'>

                <div className='control-section'>

                    <div id="target">

                        <ul>

                            <li>

                            <span className="e-ddb-icons e-paste e-align"></span>

                            <div className="e-div-align">

                                <b>Paste Text</b>

                                <div>Provides option to paste only the selected text.</div>

                            </div>

                            </li>

                        </ul>

                    </div>

                    <div className='dropdownbutton-section'>

                        <div id='dropdownbutton-control'>

                            <div className='row'>

                                <div className="col-xs-12 col-sm-12 col-lg-6 col-md-6">

                                    <DropDownButtonComponent target='#target'  iconCss='e-ddb-icons e-profile'>Paste</DropDownButtonComponent>

                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </div>);

    }


Sample link: https://stackblitz.com/edit/react-9fxjgn?file=index.js,index.css


Could you please check the above code and get back to us, if you need any further assistance on this. 


Regards,

YuvanShankar A


Marked as answer

TT Ton That Hung July 8, 2022 03:09 AM UTC

That's great. Thank you for your solution.



YA YuvanShankar Arunagiri Syncfusion Team July 11, 2022 04:28 AM UTC

Hi Ton,


We are happy to hear that your requirement has been fulfilled. Please get back to us if you need any further assistance on this.


Regards,

YuvanShankar A



TT Ton That Hung July 20, 2022 04:10 AM UTC

Hi YuvanShankar,

While I using the Popup templating feature of the dropdown button, the button on Popup doesn't trigger the onClick event.

Sample: https://stackblitz.com/edit/react-9fxjgn-mbcymw?file=index.js,index.css



YA YuvanShankar Arunagiri Syncfusion Team July 21, 2022 07:32 AM UTC

Hi Ton,


We have validated your reported query and prepared the sample based on your requirement. Please use the Syncfusion button component to resolve your issue and refer the below code and sample link.


[index.js]:

render() {

    return (

      <div className="control-pane">

        {/* <ButtonComponent id="btn" cssClass='e-primary' created={this.btnCreated.bind(this)} >Click</ButtonComponent> */}

        <div className="control-section">

          <div id="target">

            <ul>

              <li>

                <div className="e-div-align">

                <ButtonComponent id="btn" cssClass='e-primary' created={this.btnCreated.bind(this)} >Click</ButtonComponent>

                  <div>Provides option to paste only the selected text.</div>

                </div>

              </li>

            </ul>

          </div>

          <div className="dropdownbutton-section">

            <div id="dropdownbutton-control">

              <div className="row">

                <div className="col-xs-12 col-sm-12 col-lg-6 col-md-6">

                  <DropDownButtonComponent

                    target="#target"

                    iconCss="e-ddb-icons e-profile"

                    beforeClose={(e) => (e.cancel = true)}

                  >

                    Paste

                  </DropDownButtonComponent>

                </div>

              </div>

            </div>

          </div>

        </div>

      </div>

    );

  }

Sample link: https://stackblitz.com/edit/react-9fxjgn-juvmhj?file=index.js


Could you please check the above sample and get back to us, if you need any further assistance on this. 


Regards,

YuvanShankar A



TT Ton That Hung July 22, 2022 02:59 PM UTC

Well, thanks for your solution.



YA YuvanShankar Arunagiri Syncfusion Team July 25, 2022 04:10 AM UTC

Hi Ton,


We are happy to hear that your requirement has been fulfilled. Please get back to us if you need any further assistance on this.


Regards,

YuvanShankar A



TT Ton That Hung March 20, 2023 07:50 AM UTC

Hi YuvanShankar,

I have a problem when I use TextboxComponent on the Popup. I can't enter space character.

Link sample:https://stackblitz.com/edit/react-9fxjgn-3wgsdn?file=index.js,package.json


How can I config to fix this problem?


Thanks.



YA YuvanShankar Arunagiri Syncfusion Team March 20, 2023 11:33 AM UTC

Hi Ton,


We have checked your reported query and to resolve this issue, kindly add the “e-edit-template” to input element which placed within the dropdown button popup element shown as below.


<TextBoxComponent ref={(scope=> textObj = scope} created={onCreated.bind(this)}/>

                  <br />

                  <input className="e-edit-template"/>

…….

function onCreated() {

      textObj.element.classList.add("e-edit-template");

    }


Sample link: https://stackblitz.com/edit/react-9fxjgn-clngfv?file=index.js


Get back to us if you need any further assistance on this. 



TT Ton That Hung March 21, 2023 03:28 AM UTC

Thanks for your support.

It's work for me.

I have 2 questions about this solution:

  1. why add class "e-edit-template" to the list, what is the mechanism behind it.
  2. Later when I upgrade to higher versions of syncfusion, will this hotfix still work?

I'm a bit worried about this fix.

Thank you so much.








YA YuvanShankar Arunagiri Syncfusion Team March 21, 2023 08:43 AM UTC

Ton,

 

Query: why add class "e-edit-template" to the list, what is the mechanism behind it?

In the source level, the space key action for text boxes is prevented by the dropdown button keyboard navigation action. If the target has an element with ‘e-edit-template’ class name, then we have prevented the dropdown button keyboard action and enabled the popup element key action.


Query: Later, when I upgrade to higher versions of syncfusion, will this hotfix still work?

Yes, it is a stable fix, and it is considered for all our higher/upcoming versions of Syncfusion packages.


Get back to us if you need any further assistance on this.




TT Ton That Hung March 27, 2023 04:02 AM UTC

Thanks for your support.



YA YuvanShankar Arunagiri Syncfusion Team March 28, 2023 11:11 AM UTC

You are welcome, Ton. Please get back to us if you need any further assistance on this.


If that post is helpful, please consider accepting it as the solution so that other members can locate it more quickly.


Loader.
Up arrow icon