fix: don't expose handler-less TouchableRipple as a disabled control - #5071
fix: don't expose handler-less TouchableRipple as a disabled control#5071lukemorawski wants to merge 1 commit into
Conversation
| style={[styles.icon, style]} | ||
| onPress={onPressHandler} | ||
| disabled={disabled} | ||
| onPress={onPress} |
There was a problem hiding this comment.
what do you think about making it non-accessible when it has no onPress?
| onPress={onPress} | |
| onPress={onPress} | |
| accessible={Boolean(onPress)} | |
| role={onPress ? 'button' : 'none'} |
updated snapshot still has accessible={true} & role="button". RN Web maps that role to a native <button>, focusable={false} only removes it from tab order.
that's why screen readers may still announce actionable button that does nothing
There was a problem hiding this comment.
what about keeping existing disabled-color precedence here & handling the TextInput.Icon case locally?
moving customIconColor first changes every <IconButton disabled iconColor="......" />.
Button still give disabled colors precedence (link) while IconButton docs list onSurfaceDisabled (link)
however, if this global behavior change is intentional, maybe we can at least document it?
Motivation
TouchableRipplehadconst disabled = disabledProp || !hasPassedTouchHandler, so anything without a press handler got announced as a disabled control. Split into two flags:Non-controls now render a plain
Animated.Viewinstead of aPressable.Worth knowing why it drops the
Pressableinstead of just passing the caller'sdisabledthrough:disabledalso gates touch-responder claiming (Pressability.js:448,onStartShouldSetResponder: () => !disabled). Fixing only the announcement turns claiming on, so handler-less ripples start swallowing taps.TextInputwraps its field and icons in<Pressable onPress={focusInput}>(TextInput.tsx:352), so tapping a decorative icon stopped focusing the field. Tests stayed green through that.Two things kept on purpose, both break stuff if dropped:
accessible={rest.accessible !== false}, or a checkedCheckboxItemwith no handler loses its role and state.focusable={rest.focusable ?? false}, or on web the icon lands in the tab order, since RNW turnsrole="button"into a real<button>.Related issue
Closes #5070
Supersedes #5011, which fixes the same symptom in
Chip.tsxonly by injecting an emptyonPress. That swaps a false "disabled" for a false "enabled" and leaves the other 21 consumers broken.Test plan
Lint, typecheck and tests pass: 55 suites, 742 tests, 169 snapshots.
The suite can't catch this though. It renders an element tree, never a DOM or a native view, and jest never loads
TouchableRipple.tsxat all. So it's checked on device, example app, TextInput screen with "Leading icon" on. Leading magnifier has no handler, trailing clear button does.enabled: false->trueenabled="false"->"true"<button disabled>-> goneWeb also keeps
tabindex="-1"on the decorative icon.Snapshots are noisy but mechanical: 80 elements drop the
Pressablehandlers and the always-undefineda11y scaffolding. Checked every style key/value pair, nothing net-added. Somearia-*show up raw now becauseView.jsdoes that folding at runtime and the jest preset mocksView.Two extras, worth a look
TextInputIconwas faking disabled by nulling its own handler, which only worked because of this bug. Now passesdisabledthrough.IconButton.getIconColorreturned ondisabledbefore readingcustomIconColor, so onceTextInputIconforwardeddisableda disabled field's icon lost its custom and error colour. Reordered so an explicit colour wins, opacity still shows disabled. No snapshot churn, so nothing else passes both, but it is a public component behaviour change and the bit I'd most want checked.