Commit ac51096
fix: fix drawer tab order on web for better accessibility (react-navigation#12616)
**Motivation**
Currently, the Drawer component on web has an incorrect tab order when
positioned on the left side of the screen and when the `drawerType` is
`'permanent'` . This creates accessibility issues for keyboard users and
those using assistive technologies, as the tab sequence doesn't follow a
logical left-to-right order when the drawer is on the left side.
**Problem**
The current implementation uses `flex-direction: row-reverse` to
position the drawer on the left side. While this achieves the desired
visual layout, it creates an incorrect tab order because the DOM
elements are rendered in a sequence that doesn't match the visual
layout. This violates accessibility best practices and makes navigation
difficult for keyboard users.
**Solution**
This PR fixes the tab order by:
1. Removing the use of `flex-direction: row-reverse`
2. Ensuring the DOM elements are written in the proper left-to-right
sequence based on the drawer position
3. Maintaining the same visual layout while improving accessibility
See [MDS Documentation on
tabindex](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/tabindex)
> Warning: You are recommended to only use 0 and -1 as tabindex values.
**Avoid using tabindex values greater than 0 and CSS properties that can
change the order of focusable HTML elements (Ordering flex items)**.
Doing so makes it difficult for people who rely on using keyboard for
navigation or assistive technology to navigate and operate page content.
**Instead, write the document with the elements in a logical sequence.**
**Test plan**
1. The change is reflected on `Drawer Layout` in the example app.
2. Change the drawer type to "permanent" and ensure that the drawer
position is set to "left"
3. Using the `tab` key on the keyboard, tab through the elements.
4. See that the tab order is in sequence. `Shift + tab` to tab in
reverse.
5. Change the drawer position to "right"
6. Again, tab through the elements, and see that the tab order is in
sequence, matching the visual layout.
**Screenshots**
**Before (Incorrect tab order)**
https://github.com/user-attachments/assets/fa92e69b-ebfc-49f9-88bb-0ff7788da9fe
**After (Corrected tab order)**
https://github.com/user-attachments/assets/735f63d2-818e-455b-94c3-de3c847f3a95
**Everything working as before**
https://github.com/user-attachments/assets/f163f9c7-6ce4-4650-b8c5-2cb610aa084e
---------
Co-authored-by: Satyajit Sahoo <[email protected]>1 parent e95e8bb commit ac51096
File tree
2 files changed
+48
-49
lines changed- example/src/Screens
- packages/react-native-drawer-layout/src/views
2 files changed
+48
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
Lines changed: 47 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
108 | 127 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 128 | + | |
| 129 | + | |
121 | 130 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 131 | + | |
154 | 132 | | |
155 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
156 | 143 | | |
157 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
158 | 155 | | |
159 | 156 | | |
160 | 157 | | |
161 | 158 | | |
162 | 159 | | |
| 160 | + | |
163 | 161 | | |
164 | 162 | | |
165 | 163 | | |
| |||
172 | 170 | | |
173 | 171 | | |
174 | 172 | | |
| 173 | + | |
175 | 174 | | |
176 | 175 | | |
0 commit comments