ally.js icon indicating copy to clipboard operation
ally.js copied to clipboard

Making it possible to distinguish touch/mouse as source of focus

Open darobin opened this issue 8 years ago • 3 comments

Right now data-focus-source makes it possible to tell keyboard from pointer as the source of focus. We (@halmos and I) would like to be able to further distinguish different types of pointers. The use case is to be able to provide a thicker (or otherwise more visible) focus outline on touch, because you can't see what's under your finger.

In terms of how this gets exposed, I don't think we can change data-focus-source without breaking compatibility. So that would always reflect "pointer". But we can add a second data attribute, say data-pointer-type, that could contain touch/mouse/stylus/catpaw/headbang/etc.

In terms of implementation, just giving it a quick look I believe that https://github.com/medialize/ally.js/blob/master/src/observe/interaction-type.js could expose that distinction (since it knows what event it's reacting to) by incrementing/decrementing modality-specific counters in addition to the pointer one, and then that https://github.com/medialize/ally.js/blob/master/src/style/focus-source.js#L52 could simply make use of that information.

We're open to other approaches of course, this is just what we've thought up. If you're up for this, we'd be happy to file a PR.

darobin avatar Jan 30 '17 21:01 darobin

I like your approach! Much simpler than what I had in mind.

I think I'd call the attribute data-focus-source-pointer="<value>". And <value> would returned by observe/interaction-type as a third property called pointerType, with its value defined by event.pointerType. I assume there's no mix'n'match, so modality-specific counters don't seem necessary. <value> would default to null, be "touch" for event.type === "touchstart", "mouse" for event.type === "mousedown" and otherwise whatever event.pointerType returns.

of course I'd love a PR for this :)

rodneyrehm avatar Jan 30 '17 22:01 rodneyrehm

how is this going looking into this?

alexanderbrown21 avatar Feb 21 '18 00:02 alexanderbrown21

I'm not aware anyone has put work into this yet. Are you up for it?

rodneyrehm avatar Feb 21 '18 08:02 rodneyrehm