Create a click event on a child element
up vote
0
down vote
favorite
Given a component defined like:
export default class KeyboardShortcut extends React.Component
componentDidMount()
window.addEventListener('keydown', e => this.handleKeyDown(e));
componentWillUnmount()
window.removeEventListener('keydown', this.handleKeyDown);
handleKeyDown(e)
if (e.key === 'c')
// what goes here?
render()
return this.props.children
How do I generate, or trigger, a click event on the children when the type of keyboard event being handled in handleKeyDown
(i.e., the pressing of the letter c) happens?
reactjs
add a comment |
up vote
0
down vote
favorite
Given a component defined like:
export default class KeyboardShortcut extends React.Component
componentDidMount()
window.addEventListener('keydown', e => this.handleKeyDown(e));
componentWillUnmount()
window.removeEventListener('keydown', this.handleKeyDown);
handleKeyDown(e)
if (e.key === 'c')
// what goes here?
render()
return this.props.children
How do I generate, or trigger, a click event on the children when the type of keyboard event being handled in handleKeyDown
(i.e., the pressing of the letter c) happens?
reactjs
Depends on whatchildren
is. There may be no easy way, or you may have XY problem. Please, provide stackoverflow.com/help/mcve
– estus
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Given a component defined like:
export default class KeyboardShortcut extends React.Component
componentDidMount()
window.addEventListener('keydown', e => this.handleKeyDown(e));
componentWillUnmount()
window.removeEventListener('keydown', this.handleKeyDown);
handleKeyDown(e)
if (e.key === 'c')
// what goes here?
render()
return this.props.children
How do I generate, or trigger, a click event on the children when the type of keyboard event being handled in handleKeyDown
(i.e., the pressing of the letter c) happens?
reactjs
Given a component defined like:
export default class KeyboardShortcut extends React.Component
componentDidMount()
window.addEventListener('keydown', e => this.handleKeyDown(e));
componentWillUnmount()
window.removeEventListener('keydown', this.handleKeyDown);
handleKeyDown(e)
if (e.key === 'c')
// what goes here?
render()
return this.props.children
How do I generate, or trigger, a click event on the children when the type of keyboard event being handled in handleKeyDown
(i.e., the pressing of the letter c) happens?
reactjs
reactjs
asked yesterday
Rodrigo Deodoro
863713
863713
Depends on whatchildren
is. There may be no easy way, or you may have XY problem. Please, provide stackoverflow.com/help/mcve
– estus
yesterday
add a comment |
Depends on whatchildren
is. There may be no easy way, or you may have XY problem. Please, provide stackoverflow.com/help/mcve
– estus
yesterday
Depends on what
children
is. There may be no easy way, or you may have XY problem. Please, provide stackoverflow.com/help/mcve– estus
yesterday
Depends on what
children
is. There may be no easy way, or you may have XY problem. Please, provide stackoverflow.com/help/mcve– estus
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237809%2fcreate-a-click-event-on-a-child-element%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Depends on what
children
is. There may be no easy way, or you may have XY problem. Please, provide stackoverflow.com/help/mcve– estus
yesterday