Open brandonmcconnell opened 6 months ago
I presume this is related to the idea that, if you're holding a smartphone in your right hand, it's easier to access controls on the right and bottom sides, while top/left controls require either an uncomfortable reach or switching to using both hands?
If so, I definitely sympathize with the concern, and think there's potential here. However, is there any way to actually detect this? I'm not familiar with whatever APIs might exist. I know that the OSK can be switched to a mode that favors one hand or the other by shifting slightly to one side, but I only ever activate that by accident.
The big issue with new user-preference MQs is always going to be the actual detection. It can be the best idea in the world, but if no OS exposes that the user wants it (and the browser doesn't hack their own detection/preference-recording on top), we can't actually hang an MQ off of it.
@tabatkins Thanks! Yeah, that's part of it, and to better support persons with disabilities.
Good call-out on the detection. My thought was to reach out to browsers as well and add support there first, and then work outward on getting that supported natively at the OS level, but perhaps I'm working backward here and should start OS-first.
I think this is one of the annoying cases that has to be worked at both ends simultaneously. :(
Gotcha. I'll start reaching out to OS teams to see if I can gain some traction on that end. @argyleink recommended I reach out to Android OS to start, on Google's issue tracker.
I don't think the logical part of it is useful or works. mediaqueries work from the initial styles, so no amount of styling within the pages can change the mapping between logical and physical. Even if that did work, I have a hard time imagining users who hold their phone in the right hand when reading English, the left hand when reading arabic, and holding it from the top when reading vertical Japanese, so I don't think there's a need.
@frivoal I agree completely. I was seeking validation on that, so thank you!
I'll remove that section to avoid confusion.
Related Android OS issue opened here: https://issuetracker.google.com/issues/336589276
@brandonmcconnell Do you see this as a mobile only thing? Or are you expecting desktop users to use this? I ask for clarity. I think you have a good concept here, I'm just not sure of the execution of it.
One of the reasons is that while we've seen success with reflow for RWD, we still struggle to get developers to support orientation on native mobile apps. Considering these settings will have multiple variants we will need to convince designers as well. If the designers don't adopt flexible layouts, then this will go nowhere and I don't see them wanting to do this.
But the flexible layouts themselves may be an issue. If a site is coded with the navigation on top and the user sets it as preference for the bottom, what does the reading and focus order look like?
@nattarnoff I've considered the same question.
While developers could use this in either desktop or mobile, I could see developers implementing this specifically for touch devices by combining prefers-interaction-direction
with a pointer: coarse
check, perhaps sometimes paired with a size query as well:
nav {
position: fixed;
top: 0;
}
form#login {
float: left;
}
@media (pointer: coarse) {
@media (prefers-interaction-direction: bottom) and (width < 767px) {
nav {
top: unset;
bottom: 0;
}
}
@media (prefers-interaction-direction: right) {
form#login {
float: right;
}
}
}
In terms of OS, prominent device companies like Google/Android and Apple would likely implement this feature exclusively on mobile and tablet devices, at least to start, unless the WCAG makes a solid argument to include it across all device types.
I see a case being made for less able persons preferring most interactions to be on one side of the screen to prevent having to move the cursor so far for every interaction. Many applications will inevitably be slow to adopt this, but providing a way for applications to hook into this preference would allow those companies and developers with ample bandwidth to cater to those specific needs, which would be a great convenience to those who need it.
Accessibility features like prefers-interaction-direction
also have the potential to help companies and developers who use them. By removing unnecessary friction in the user journey, they can better serve their users and customers and increase their potential audience.
I wonder if a better argument can be made for XR than for mobile. Maybe detection (e.g., Apple Vision Pro) is possible but maybe it's only stored in user preferences for the device to start with detection coming as hardware/OS expands sensors.
@AutoSponge Interesting! I could see this being possibly helpful if implemented in XR/AR as well, though one of the primary use cases would be mobile as that addresses a common problem I and others face when crafting user interfaces.
@nattarnoff Re designer/developer adoption, specifically your note on low orientation
usage, I would make the argument that exposing that option does allow companies and developers to cater to that orientation when possible.
Adoption is important
The goal of implementing this feature, as with many accessibility issues, is to capture and expose the preference so designers/developers can tap into it.
The next journey will be adoption, which is an equally vital but arguably separate concern. Through education and social efforts, we can work to make these features—and others like them—ones that designers/developers will tap into.
TL;DR:
But the flexible layouts themselves may be an issue. If a site is coded with the navigation on top and the user sets it as preference for the bottom, what does the reading and focus order look like?
@nattarnoff Reading order often remains unchanged when using features like this, and follows the flow of the order of elements in the DOM.
For example, the reading order of the content here remains "form ➞ main" regardless of their visually rendered order:
<div id="wrapper">
<form id="login">…</form>
<main>
…
</main>
</div>
#wrapper {
display: flex;
}
main {
flex: 1;
}
@media (prefers-interaction-direction: right) {
main {
order: -1;
}
}
See example: https://codepen.io/brandonmcconnell/pen/NWmozxO/8b53be8b61fbb92d6223e1b70c3d9922
Why should top right
be equivalent to separate occurrences with top
and right
? My first intuition was to interpret top
and bottom
as indicating preference for vertical progression of content following semantically (which is more common, and thus designers are taught to avoid horizontal scrolling more than vertical). So, top right
would mean that interacting from top to bottom is preferred in the vertical direction, from right to left is preferred in the horizontal direction, but vertical arrangement is preferred as principal. The latter would be reversed with right top
. Makes sense?
@ByteEater-pl The problem this solves is less about the flow of content and more about which side of each axis a user prefers interactive elements to be on.
There would be no difference between top right
and right top
.
Here are some examples, one per axis:
X (left/right) — login form on left vs. right side
Y (top/bottom) — search bar on top vs. bottom side
There are rare instances I can think of where someone may want to query both axes together, so it may be more confusing to allow those to be queried together. This is certainly something I would like to collect more feedback on.
One example of why querying both together could be problematic is if someone queries both together to try to set up a corner-specific element without accounting for a use case where someone has no preference set on only one axis, which would be extremely common.
.corner-element {
position: fixed;
@media (prefers-interaction-direction: no-preference) { inset: auto 0 0 auto; }
@media (prefers-interaction-direction: top left) { inset: 0 auto auto 0; }
@media (prefers-interaction-direction: top right) { inset: 0 0 auto auto; }
@media (prefers-interaction-direction: bottom left) { inset: auto auto 0 0; }
@media (prefers-interaction-direction: bottom right) { inset: auto 0 auto 0; }
}
This is a non-issue if—like with prefers-color-scheme
— we don't include a no-preference
option, but I think including no-preference
might be more valuable for prefers-interaction-direction
as it may be considered a more impactful accessibility setting.
If the system default were bottom
and right
, apps might all start aligning content to cater to bottom
and right
preferences when, in most cases, this is not needed. With that in mind, users would enable this preference on a purely opt-in basis, and each axis would be set to no-preference
by default.
In cases like the example above, it might be simpler to use one rule per axis:
.corner-element {
position: fixed;
@media (prefers-interaction-y: no-preference) or (prefers-interaction-y: bottom) {
bottom: 0;
}
@media (prefers-interaction-y: top) {
top: 0;
}
@media (prefers-interaction-x: no-preference) or (prefers-interaction-x: right) {
right: 0;
}
@media (prefers-interaction-x: left) {
left: 0;
}
}
We can simplify further by setting defaults on the element styles itself, outside the queries:
.corner-element {
position: fixed;
bottom: 0;
right: 0;
@media (prefers-interaction-y: top) {
top: 0;
bottom: auto;
}
@media (prefers-interaction-x: left) {
left: 0;
right: auto;
}
}
I anticipate most developers using prefers-interaction-direction
this way.
It would still be vital to include no-preference
as an option here, as it is very different from prefers-color-scheme,
which deprecated the no-preference
option.
If this is about which side of the page interactive elements should be on, that's a very different thing from a "direction of flow" preference which is what this sounds like. Renaming; we can bikeshed more later but at least let's get the basic concept up front.
@fantasai Thanks! Yes, I can see how that could be confusing. This is more about the interaction
side, so that name sounds fine to me for now.
I'd like to mention an additional supporting use (particularly for including top and bottom) case I've come across for several years (partly as a vision-impaired person, but I think this generalises pretty well). We have had widescreen (and now even wider-screen) monitors for some time, and a lot of vertical screen space is wasted by things like toolbars that run along the top/bottom of apps. For me, this is exacerbated by my use of UI scaling to increase the size of UI controls and text - the wasted vertical space gets pretty big at times. I would love to be able to move some toolbars to the sides instead.
There are examples in some GUI environments where you can place things like taskbars/panels on the top/bottom or either side - far fewer extend this to general app toolbars too. Though some environments and applications let you position toolbars on any of the four sides. E.g. Inkscape (screenshots page) even automatically puts some toolbars on the left/right (rather than top/bottom) according to screen space, and it can position tool pallettes/docked windows on the left or right.
It would be great if mainstream operating systems and their standard GUI widget libraries would offer this flexibility, including for in-app toolbars. The web could leapfrog other platforms here. We discussed this on the Accessible Platform Architectures WG call today (thanks to @AutoSponge for the 'heads up' about this conversation), though this comment represents my personal (albeit I hope helpful as a datum point) perspective.
Introduction
This proposal introduces a new media query,
prefers-interaction-direction
, which allows web developers to adapt their layouts and user interfaces based on the user's preferred interaction direction. The media query informs the website about the optimal placement of interactive elements, such as login forms and navigation bars, to enhance user experience and accessibility.This could be very helpful to users for several reasons:
Syntax
The
prefers-interaction-direction
media query accepts the following values:left
right
top
bottom
The media query can be used as follows:
Combining Interaction Directions
The
prefers-interaction-direction
media query allows for combining interaction directions to target specific user preferences.For example, these two would be equivalent:
This feature enables web developers to create more tailored user experiences based on the combination of the user's preferred interaction directions.
Overriding the User Preference
To provide flexibility and control to web developers, a new CSS property,
interaction-direction
, is introduced to override the user's preferred interaction direction. This property functions similarly to thecolor-scheme
property, which overrides theprefers-color-scheme
media query.The
interaction-direction
property accepts the same values as theprefers-interaction-direction
media query, allowing web developers to explicitly set the interaction direction for specific elements.Any of the "Single-direction values" or "Direction-paired values" listed above could also be used with
only
to override default UA behavior.One consideration is whether "Direction-paired values" should support
only
used once for both values or if it should be used per value as needed.Prior Art
References and inspiration
Conclusion
The introduction of the
prefers-interaction-direction
media query and theinteraction-direction
property would empower developers to create more dynamically responsive and accessible user interfaces. By adapting to the user's preferred interaction direction, websites can enhance the user experience and cater to diverse user preferences and needs.