microsoft / fast

The adaptive interface system for modern web experiences.
https://www.fast.design
Other
9.28k stars 594 forks source link

Fix: Tabs switch on mousedown and checks for defaultPrevented #6890

Closed scomea closed 7 months ago

scomea commented 9 months ago

Tabs should select on mousedown rather than click, this seems typical and makes implementing draggable tabs easier in that the tab being dragged should be the selected one so selection should happen before mouseup.

Addtionally, added checks for defaultPrevented in the event handlers. Tabs can have things like clickable close buttons that may want to block default handling.

🎫 Issues

Ad-hoc. Stuff I'm noticing while implementing.

✅ Checklist

General

Component-specific

bheston commented 7 months ago

Came across the wcag requirements for pointer cancellation: https://www.w3.org/TR/WCAG21/#pointer-cancellation which might apply here.

Is it possible to support dragging to reorder tabs without them being selected?

scomea commented 7 months ago

Came across the wcag requirements for pointer cancellation: https://www.w3.org/TR/WCAG21/#pointer-cancellation which might apply here.

Is it possible to support dragging to reorder tabs without them being selected?

My "model" was the way browser tabs on Edge work (ie. select on mousedown, you're dragging the selected tab) as that seemed a reasonable approach. Happy to look at other approaches. I'm not committed to any particular mechanic.

scomea commented 7 months ago

All the browsers look to have the "select on mousedown" behavior, as does VSCode. It seems like a reasonable design decision either way. If we're not planning on implementing drag and drop maybe the right approach would be to make it easy to extend the component to implement either? ie. protected functions and or by wiring up the template differently.

bheston commented 7 months ago

All the browsers look to have the "select on mousedown" behavior, as does VSCode. It seems like a reasonable design decision either way. If we're not planning on implementing drag and drop maybe the right approach would be to make it easy to extend the component to implement either? ie. protected functions and or by wiring up the template differently.

I'm on board with that. There have been a few other similar changes recently. The default case here is not to have drag and drop, so to align with a11y best practices I like the idea of leaving the cancel capability. I still think drag could happen without a tab becoming selected, but it might not always make sense.