-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Description
I am trying to attach a dropdown to a button. I need my application to build with no errors!
Steps to reproduce
This is my component where I am trying to attach a dropdown to a button:
import {
IIgrButtonBaseProps,
IgrButton,
IgrButtonBase,
IgrButtonModule,
IgrDropdown,
IgrDropdownItem,
IgrDropdownItemModule,
IgrDropdownModule
} from 'igniteui-react';
import { useRef } from 'react';
IgrButtonModule.register();
IgrDropdownItemModule.register();
IgrDropdownModule.register();
export default function IgView() {
const dropdown = useRef<IgrDropdown>(null);
const button1 = useRef<IgrButton>(null);
const button2 = useRef<IgrButton>(null);
const button3 = useRef<IgrButton>(null);
function buttonClick1(ev: IgrButtonBase<IIgrButtonBaseProps>): void {
dropdown.current.toggleTarget(ev.i.nativeElement);
}
function buttonClick2(ev: any): void {
dropdown.current.toggleTarget(ev.i.nativeElement);
}
function buttonClick3(): void {
dropdown.current.toggleTarget(button3.current);
}
return (
<div>
<IgrButton ref={button1} clicked={buttonClick1}><span>Button 1</span></IgrButton>
<IgrButton ref={button2} clicked={buttonClick2}><span>Button 2</span></IgrButton>
<IgrButton ref={button3} clicked={buttonClick3}><span>Button 3</span></IgrButton>
<IgrDropdown ref={dropdown}>
<IgrDropdownItem><span>Option</span></IgrDropdownItem>
</IgrDropdown>
</div>
);
}Result
buttonClick1 is able to show the dropdwon on button click. However, the build fails with Property 'nativeElement' is protected and only accessible within class 'ButtonBase' and its subclasses.
buttonClick2 is able to show the dropdown on button click. However, the build fails with Unexpected any. Specify a different type.
buttonClick3 builds successfully but is not able to show the dropdown on button click it fails on run time with element.addEventListener is not a function on _setTarget of dropdown.
Expected result
Should be able to attach the dropdown to a button (or any other component) and show it on click with no build or runtime errors.