Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic hotkeys for multiple components. #292

Open
gamevnlc opened this issue Sep 20, 2020 · 0 comments
Open

Dynamic hotkeys for multiple components. #292

gamevnlc opened this issue Sep 20, 2020 · 0 comments

Comments

@gamevnlc
Copy link

gamevnlc commented Sep 20, 2020

Hello, I have use HotKeys to render multiple components with a different hotkey. Then I realize I need to focus on components to activate the hotkey. I don't want to do that. I change it to multiple GlobalHotKeys to avoid focus on each component. When I change to GlobalHotKeys and active hotkey the state of the parent does not change. It only affects the first component.

here my code


export const SingleMediaBox = ({media, project, keyboard}) => {
    const {labels} = project;
    const [modalShow, setModalShow] = useState(null);
    const mediaId = media.id;
    const keyMap = {
        ZOOM: `shift+${keyboard}`
    };

    const handlers = {
        ZOOM: event => setModalShow(preState => {
            console.log(preState);
            console.log(media.id);
            if (preState) {
                return null
            } else {
                return media.id
            }
        })
    };

    return (
        <Col xs={4} className="single-media">
            <GlobalHotKeys keyMap={keyMap} handlers={handlers}>
                <p className="mb-2">{media['media_id']}</p>
                <Card>
                    <Media/>
                    <Card.Body>
                        <div>
                            <a href={media['media_url']} target="_blank" className="pr-2"
                               rel="noopener noreferrer">Original</a>
                            {/*<a href="#" className="pr-2">Zoom</a>*/}
                            {/*<Link >Test</Link>*/}
                        </div>
                        {labels.map((label) => (
                            <Form.Check
                                name={media.id}
                                type="radio"
                                label={label.name}
                                key={`label-${label.id}`}
                            />
                        ))}
                    </Card.Body>
                </Card>
                <ModalMedia show={modalShow === mediaId} onHide={() => setModalShow(null)} media={media}/>
            </GlobalHotKeys>
        </Col>
    )
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant