Skip to content

fix(filter-chip,suggestion-chip): support a11y high contrast mode on chip components#1195

Open
paulinea wants to merge 7 commits intodevelopfrom
1181-a11y-support-high-contrast-mode-on-chip-component
Open

fix(filter-chip,suggestion-chip): support a11y high contrast mode on chip components#1195
paulinea wants to merge 7 commits intodevelopfrom
1181-a11y-support-high-contrast-mode-on-chip-component

Conversation

@paulinea
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.orange.ouds.core.component.OudsFilterChip
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two new imports are unused.


@Composable
override fun Preview(theme: OudsThemeContract, darkThemeEnabled: Boolean, highContrastModeEnabled: Boolean, parameter: Any?) {
@Suppress("UNCHECKED_CAST")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This annotation is not necessary because there is no preview parameter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if high contrast is correct for Sosh since I find that the white tick is easier to read compared to the black one. What do you think?

The same comment applies to the Wireframe theme.

}.value
OudsChipState.Enabled -> when {
// In order to reach the a11y AAA level, when high contrast mode is enabled, the enabled chip border color must use `color.content.default` token
LocalHighContrastModeEnabled.current -> OudsTheme.colorScheme.content.default
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use this PR to update the isHighContrastModeEnabled method in ContextExt.kt since a new API is available with API level 36 (I also removed @SuppressLint("DiscouragedPrivateApi") which does not seem useful):

@SuppressLint("PrivateApi")
internal fun Context.isHighContrastModeEnabled(): Boolean {
    val accessibilityManager = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager

    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) {
        accessibilityManager.isHighContrastTextEnabled
    } else {
        with(accessibilityManager) {
            // Workaround to access mIsHighTextContrastEnabled field because it is hidden with a @UnsupportedAppUsage annotation
            // On some OS versions this field is named mIsHighContrastTextEnabled
            tryOrNull { javaClass.getDeclaredField("mIsHighTextContrastEnabled") }
                .orElse { tryOrNull { javaClass.getDeclaredField("mIsHighContrastTextEnabled") } }
                ?.also { it.isAccessible = true }
                ?.getBoolean(this)
                .orElse { false }
        }
    }
}

There is also a bug with this method because the app needs to be restarted in order to take the new accessibility setting into account. We can probably open a bug and check this later.

OudsChipState.Pressed -> colorContentSelectedPressed
OudsChipState.Disabled -> colorContentSelectedDisabled
}.value
OudsChipState.Enabled -> if (LocalHighContrastModeEnabled.current) OudsTheme.colorScheme.content.default else colorContentSelectedTickEnabled.value
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rules for the high contrast mode in chips seems different from the high contrast mode in controls. Do you know where I can find them?

@paulinea paulinea force-pushed the 1181-a11y-support-high-contrast-mode-on-chip-component branch from a75b4c8 to d42deab Compare April 9, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[A11Y] Support High-contrast mode on chip component

2 participants