Button ref uses different ref than Popup?

1 Answer 69 Views
Button Popup
Dervis
Top achievements
Rank 1
Dervis asked on 12 Nov 2021, 10:49 AM

Basically I want to achieve this https://www.telerik.com/kendo-react-ui/components/popup/ (using React, hooks and TS) example but instead of using the HTML Button I want to replace it with the Kendo-UI Button component. So when I replace the <button> element with the Kendo-UI Button I get type Errors for the ref.

How do I fix this?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 12 Nov 2021, 12:46 PM

Hello Dervis,

The reference of the KendoReact Button points to the component and not to the rendered "button" element, which will cause problems with the anchor property of the Popup. Additionally, you need to change the type to Button when getting the reference. For your convenience, following is an example with KendoReact Button set as anchor of the Popup:

Please give this a try and let me know if everything works as expected with the suggested changes.

 

Regards,
Konstantin Dikov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Dervis
Top achievements
Rank 1
commented on 12 Nov 2021, 12:53 PM

Hi Konstantin,

Thank you for your answer! That part works now but I still get the following error for the Button ref props:

Type '{ ref: any; onClick: () => void; togglable: true; }' is not assignable to type 'ButtonProps'.
  Property 'ref' does not exist on type 'ButtonProps'.

How do I fix this?

Thanks in advance

Regards,

Dervis

Konstantin Dikov
Telerik team
commented on 12 Nov 2021, 01:05 PM

You will have to include "@types/react" and "@types/react-dom":

Note that the "ref" attribute is coming from React.Component, which all of our KendoReact components use as a base.

Dervis
Top achievements
Rank 1
commented on 12 Nov 2021, 01:17 PM

This worked! Thank you so much Konstantin!

Best Wishes,
Dervis

Dervis
Top achievements
Rank 1
commented on 12 Nov 2021, 01:20 PM

Oh one more question: how I would achieve this if I created the Button component in a separate file and want to import it in the PopupContainer with using forwardRef?
Dervis
Top achievements
Rank 1
commented on 12 Nov 2021, 01:22 PM

Nvm I got it!


type HelpIconButtonProps = {
    onClick: () => void;
};

const HelpIconButton = React.forwardRef<Button, HelpIconButtonProps>(({ onClick } : HelpIconButtonProps, ref) => {
    return <Button ref={ref} icon="k-icon k-i-question" type="button" aria-label="help" onClick={onClick} togglable />;
});

Tags
Button Popup
Asked by
Dervis
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or