Click Triggers Don't Work for Keyboard Interaction?

When I put a click trigger on an element, it only responds to mouse click. That trigger can’t be used with keyboard interaction unless I’m missing something. Is this a bug? Oversight?

1 Like

It works exactly like a regular click event would if adding via JS.

Keyboard presses would only apply in certain situations automatically, like if the element was using a button tag, or link with tabindex, otherwise needs separate event listeners to listen for the keypresses.

Shouldn’t the keypress listeners be added by default? Or no? It seems like if you want people to be able to click, you want them to be able to press, too.

Maybe, but having them connected as default there’d be some inconsistencies that would need to be accounted for.

For eg, in some cases you’d have things accidentally triggering twice, where both the click event and keydown event are happening at once. (for eg tabbing over to a button and pressing space would trigger both - so if an action was added to toggle a class or something, it’ll both toggle on and off at the same time.

There may be lots of things like this. Another example off the top of my head, is situations such as users adding a click event to reveal a form (like clicking a card that opens to show a form), then after clicking, if the user tabs across the form and presses space inside the form when filling in the details it could trigger the keydown and therefore repeat the same action and hide the form.

tbh I think it’ll be hard to cover all scenarios and have it just ‘work’ automatically from this UI for any element type. These types of things are usually so specific based on the expected action from the user (which is obv only known to the person building the site or element).

The other option would be that they add keydown, keyup etc as new triggers that can be used, alongside the others, but then the bricks user is taking on the burden of needing to understand the nuances before being able to use the interactions. Only people who already know this stuff would be able to actually use it. Maybe they decided that just getting people to stick to using links and buttons with the clicks is the simpler approach :person_shrugging: