cashapp / paparazzi

Render your Android screens without a physical device or emulator
https://cashapp.github.io/paparazzi/
Apache License 2.0
2.29k stars 214 forks source link

Material 3 `ModalBottomSheet` does not display Accessibility #1577

Closed Jonas-I closed 1 month ago

Jonas-I commented 1 month ago

Description When using the ModalBottomSheet from Material3, the accessibility for the components inside the Bottom Sheet is not rendered. The Bottom Sheet also takes up the width of the entire image rather than width of the device.

It is possible that this issue is due to the component being a modal which overlays the main UI instead of being a part of the screen layout. Using a regular BottomSheetScaffold would output the expected result.

Steps to Reproduce To display the BottomSheets, we have to set the sheetState to have an initialValue of Expanded.

For the ModalBottomSheet, we can use this test:

class ModalBottomSheetTest {

    @get:Rule
    val paparazzi = Paparazzi(renderExtensions = setOf(AccessibilityRenderExtension()))

    @Test
    @OptIn(ExperimentalMaterial3Api::class)
    fun modalBottomSheetTest() {
        paparazzi.snapshot {
            ModalBottomSheet(
                onDismissRequest = {},
                sheetState = SheetState(
                    skipPartiallyExpanded = true,
                    density = LocalDensity.current,
                    initialValue = Expanded,
                ),
            ) {
                Text(text = "Text 2")
            }
            Text(text = "Text 1")
        }
    }
}

For the BottomSheetScaffold, we can apply a similar implementation:

class BottomSheetScaffoldTest {

    @get:Rule
    val paparazzi = Paparazzi(renderExtensions = setOf(AccessibilityRenderExtension()))

    @Test
    @OptIn(ExperimentalMaterial3Api::class)
    fun bottomSheetScaffold() {
        paparazzi.snapshot {
            BottomSheetScaffold(
                scaffoldState = rememberBottomSheetScaffoldState(
                    bottomSheetState = SheetState(
                        skipPartiallyExpanded = true,
                        density = LocalDensity.current,
                        initialValue = Expanded,
                    )
                ),
                sheetContent = { Text(text = "Text 2") },
            ) {
                Text(text = "Text 1")
            }
        }
    }
}

Expected behavior We should expect to see accessibility semantics for content in the ModalBottomSheet.

Additional information:

Screenshots The image below renders accessibility for only the "Text 1" component, but not "Text 2". The Bottom Sheet also takes up the whole width of the image, but is overlapped by the accessibility section.

ModalBottomSheet
BottomSheetScaffold
geoff-powell commented 1 month ago

Fixed, thanks for reporting