1

I have buttons that use the react library react-ink with onClick canvas animation. That animation only works when button is clicked by mouse(cursor). In my view I use buttons that have a hotkey assigned to them and I need to trigger "click" animation even when I click hotkey on my keyboard.

I tried to use dispatchEvent to simulate click on proper height and width but its doesn't work

my example:

const el = wrapperRef.current.querySelectorAll(`[data-target="${value.id}"]`)[0]
const elPosition = el.getBoundingClientRect();
const evt = new MouseEvent("mousedown", {
              'view': window,
              'bubbles': true,
              'cancelable': true,
              'screenX': elPosition.left,
              'screenY': elPosition.top
            });
 el.dispatchEvent(evt);

// button
  <div
     data-target={props.values.id}
     role="button">
     <Ink hasTouch={false} />
  </div>
1

1 Answer 1

1

did you tried useRef() on ink button component, if it had click prop, so you can fire it like below: const btn =useref();

<Ink ref={btn} ...

in keybord event listener exec this

btn.current.click()

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.