Skip to content

Conversation

karinchechik
Copy link
Contributor

No description provided.

}

private up(key: string) {
private up(key: string, event: any) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can either use UIEvent or KeyboardEvent | MouseEvent | TouchEvent (I personally prefer the first one)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use either option, I had to declare 'event.currentTarget as SVGElement' to avoid TS error: Property 'classList' does not exist on type 'EventTarget'. I updated with the first option - UIEvent.

@karinchechik karinchechik requested a review from urish April 13, 2020 00:18
private down(key: string, event: UIEvent) {
if (!this.pressedKeys.has(key)) {
const currTarget = event.currentTarget as SVGElement;
currTarget.classList.add('pressed');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason you need the pressed class?
It seems like the :active selector that you have above already does the trick

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The active selector isn't triggered when pressing the space key, so I added this class.
But it has an isssue - while pressing space, if you press tab and press space again or click with the mouse on another button, it will display multiple buttons as pressed. I can fix the tab option by removing the class when pressing tab. But I couldn't think of a way to fix the mouse selection. Do you think I should check every button on mousedown? Got a better idea?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

So perhaps you could:

  1. For the tab issue - remove the pressed class on blur event. That's way, when you press the tab key, the element loses focus, and the highlight is gone.
  2. Make the event parameter optional and only pass it on keyboard event, so it won't get added on mouse events (this will probably solve the issue with the class sticking around when you click on the button, and then drag the mouse pointer out of the element area, which the button is still pressed)

@urish urish merged commit e963a59 into wokwi:master Apr 15, 2020
LironHazan pushed a commit to LironHazan/wokwi-elements that referenced this pull request Apr 29, 2020
* improvement: style of pressed buttons
* improvement: buttons pressed

Co-authored-by: Karin <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants