Skip to content

Commit dbd0e4a

Browse files
committed
a11y: Improve accessibility on ReactionSummaryView
1 parent 030af71 commit dbd0e4a

File tree

1 file changed

+23
-7
lines changed
  • features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary

1 file changed

+23
-7
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/reactionsummary/ReactionSummaryView.kt

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.compose.foundation.lazy.items
2727
import androidx.compose.foundation.lazy.rememberLazyListState
2828
import androidx.compose.foundation.pager.HorizontalPager
2929
import androidx.compose.foundation.pager.rememberPagerState
30+
import androidx.compose.foundation.selection.selectable
3031
import androidx.compose.foundation.shape.CornerSize
3132
import androidx.compose.foundation.shape.RoundedCornerShape
3233
import androidx.compose.material3.ExperimentalMaterial3Api
@@ -45,12 +46,17 @@ import androidx.compose.ui.Alignment
4546
import androidx.compose.ui.Modifier
4647
import androidx.compose.ui.draw.clip
4748
import androidx.compose.ui.graphics.Color
49+
import androidx.compose.ui.semantics.Role
50+
import androidx.compose.ui.semantics.clearAndSetSemantics
51+
import androidx.compose.ui.semantics.contentDescription
52+
import androidx.compose.ui.semantics.semantics
4853
import androidx.compose.ui.text.style.TextOverflow
4954
import androidx.compose.ui.tooling.preview.PreviewParameter
5055
import androidx.compose.ui.unit.dp
5156
import androidx.compose.ui.unit.sp
5257
import coil3.compose.AsyncImage
5358
import io.element.android.compound.theme.ElementTheme
59+
import io.element.android.features.messages.impl.timeline.a11y.a11yReactionDetails
5460
import io.element.android.features.messages.impl.timeline.components.REACTION_IMAGE_ASPECT_RATIO
5561
import io.element.android.features.messages.impl.timeline.model.AggregatedReaction
5662
import io.element.android.libraries.designsystem.components.avatar.Avatar
@@ -140,9 +146,7 @@ private fun ReactionSummaryViewContent(
140146
HorizontalPager(state = pagerState) { page ->
141147
LazyColumn(modifier = Modifier.fillMaxHeight()) {
142148
items(summary.reactions[page].senders) { sender ->
143-
144149
val user = sender.user ?: MatrixUser(userId = sender.senderId)
145-
146150
SenderRow(
147151
avatarData = user.getAvatarData(AvatarSize.UserListItem),
148152
name = user.displayName ?: user.userId.value,
@@ -166,21 +170,32 @@ private fun AggregatedReactionButton(
166170
} else {
167171
Color.Transparent
168172
}
169-
170173
val textColor = if (isHighlighted) {
171174
MaterialTheme.colorScheme.inversePrimary
172175
} else {
173176
ElementTheme.colors.textPrimary
174177
}
175-
176178
val roundedCornerShape = RoundedCornerShape(corner = CornerSize(percent = 50))
179+
val a11yText = a11yReactionDetails(
180+
emoji = reaction.key,
181+
userAlreadyReacted = reaction.isHighlighted,
182+
reactionCount = reaction.count,
183+
)
177184
Surface(
178185
modifier = Modifier
179186
.background(buttonColor, roundedCornerShape)
180187
.clip(roundedCornerShape)
181188
.clickable(onClick = onClick)
182-
.padding(vertical = 8.dp, horizontal = 12.dp),
183-
color = buttonColor
189+
.padding(vertical = 8.dp, horizontal = 12.dp)
190+
.selectable(
191+
selected = isHighlighted,
192+
role = Role.Tab,
193+
onClick = onClick,
194+
)
195+
.clearAndSetSemantics {
196+
contentDescription = a11yText
197+
},
198+
color = buttonColor,
184199
) {
185200
Row(
186201
verticalAlignment = Alignment.CenterVertically,
@@ -230,7 +245,8 @@ private fun SenderRow(
230245
modifier = Modifier
231246
.fillMaxWidth()
232247
.heightIn(min = 56.dp)
233-
.padding(start = 16.dp, top = 4.dp, end = 16.dp, bottom = 4.dp),
248+
.padding(start = 16.dp, top = 4.dp, end = 16.dp, bottom = 4.dp)
249+
.semantics(mergeDescendants = true) {},
234250
verticalAlignment = Alignment.CenterVertically
235251
) {
236252
Avatar(avatarData)

0 commit comments

Comments
 (0)