Skip to content

feat(banner)!: take text as message, make hidden content inert - #5056

Open
lukemorawski wants to merge 26 commits into
callstack:mainfrom
lukemorawski:feat/banner-a11y-inert-when-hidden
Open

lukemorawski wants to merge 26 commits into
callstack:mainfrom
lukemorawski:feat/banner-a11y-inert-when-hidden

Conversation

@lukemorawski

@lukemorawski lukemorawski commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

A hidden Banner stayed reachable, its live region was silent on Android and iOS, and a TextInput in it lost focus on each keystroke on iOS.

  • Text goes in message, the rest in content.
  • Hidden content is inert, then unmounts.
  • Announced on show only: status, or alert with urgent.
  • A focused action that goes away hands focus on.
  • At most 2 actions, inline from 600dp.

Breaking: see the migration guide.

Related issue

Fixes #5055, fixes #4178, part of #4990

Screenshots / Videos

iOS Android

Test plan

Banner example, screen reader on:

  1. Show a banner: its message is read once.
  2. Hide it: nothing in it is reachable.
  3. iOS: type in the email banner's field: it keeps focus.

@MikitasK MikitasK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks pretty solid 👍
just a few points to address before merge:

Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Outdated
const hasLiveRegion = () => Platform.OS === 'android' || Platform.OS === 'web';

// a nested <Text> would otherwise be dropped from the announcement
const extractText = (node: React.ReactNode): string =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

child.props.children breaks on any child that doesn't render its own children, so <Banner><Message /></Banner> announces nothing on iOS. React.Children is the composition problem v6 is meant to remove (#4954) - what's the alternative here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yep, and it looks like it's not just iOS. Both the android and web live regions will go empty too. Checked it: zero announceForAccessibility calls on iOS, empty announcer on Android, visible text renders fine. dead silent on every platform. Thanks for bringing that up!

i see it liek that:

  • add messageAccessibilityLabel, matching iconAccessibilityLabel in this PR
  • keep extraction as the default so plain text keeps working
  • warn in dev when extraction is empty but children are not

React.Children stays as best effort with an opt out, not as main mechanism. but i'm happy to drop extraction entirely or park this for v6 instead. any preference?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

still there on purpose, depends on the children API question John raised below. proposal is a message: string prop, then the walk goes away.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Gone: the text is a message string now and anything else goes in content, so nothing walks the children. A <Message /> goes in content, which isn't announced, next to a message.

Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved

@MikitasK MikitasK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👌

Comment thread src/components/Banner.tsx Resolved
@satya164
satya164 requested a balanced review from Copilot September 15, 2026 20:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@satya164

Copy link
Copy Markdown
Contributor

Review by Claude

Web

A banner without actions loses its bottom spacing and the icon moves to the vertical center.

Steps: render <Banner visible icon={...}> with a message that wraps to 3 or more lines and no actions.

What happens: the text sits 8px above the bottom edge (it was 16px on the base branch), so the top spacing (24px) and the bottom spacing no longer match. The icon is centered on the text block instead of aligned with the first lines.

What should happen: the same spacing and icon position as before, since the PR description does not list this as a change.

Base branch:

Web, base branch: banner without actions

This PR:

Web, this PR: banner without actions

(via Claude, verify if it makes sense)

Android

The same spacing and icon change for a banner without actions.

Steps: the same as on web.

What happens: the last line of text is 8px from the bottom edge, and the icon is centered on the text.

What should happen: 16px bottom spacing, as on the base branch.

Android, this PR: banner without actions

(via Claude, verify if it makes sense)

@satya164 satya164 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review by Claude

  • extractText (line 38) still reads child.props.children through React.Children.toArray, and the open thread on it waits for a decision. The project rule is to avoid the Children API and element inspection, so the extraction should go. On Android and web the live region can render {children} itself instead of a string, so it announces whatever the children render, including <Message />. iOS needs a string for announceForAccessibilityWithOptions, so take it from an explicit prop there, such as the messageAccessibilityLabel proposed in the thread.
  • The branch conflicts with main in Banner.tsx, the example, the tests and the snapshot. main already moved the example banner below the app bar (#5061), so the rebase should drop the onLayout padding and the absolute position from the example. (via Claude, verify if it makes sense)

Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
Comment thread example/src/Examples/BannerExample.tsx Resolved
@Doberjohn Doberjohn added this to the 6.0.0 milestone Oct 30, 2026
@Doberjohn

Copy link
Copy Markdown
Collaborator

One thing to settle while Banner is reworked: the message is still wrapped in <Text>, so anything that isn't text inside it misbehaves. The known case is #4178: on iOS, a TextInput inside a Banner loses focus on every keystroke.

Either Banner supports non-text children (render elements outside the Text), or we document that children are text only. #4179 tried the first on 5.x but broke Text and fragment children. Whichever way 6.0 goes, 5.x will follow.

@Doberjohn Doberjohn modified the milestones: 6.0.0, 6.0.0-beta.0 Nov 12, 2026
@lukemorawski
lukemorawski force-pushed the feat/banner-a11y-inert-when-hidden branch from d347dc3 to 4c8a76f Compare November 18, 2026 14:14
@lukemorawski lukemorawski changed the title fix(banner): make hidden content inert and fix live region semantics feat(banner)!: make hidden content inert and fix live region semantics Nov 18, 2026
@lukemorawski

lukemorawski commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Breaking changes (all in the migration guide)

  • Children unmount once hidden.
  • At most 2 actions, extras dropped with a dev warning.
  • Actions sit inline from 600dp. The breakpoint follows the window, not the banner.
  • Default role is status, urgent gives alert. Tests using getByRole('alert') need urgent.
  • Announced only on hidden to visible, not on mount or when urgent flips.

Focus rescue, measured on the real Banner

Removed Web (Chromium) iPhone 12 VoiceOver S23 FE TalkBack
B of A, B C C C
C of A, C A A A
only action message message message
hide back to opener no restore no restore

Web uses .focus() (message has tabIndex={-1}). Native uses sendAccessibilityEvent when a screen reader is on and the action was pressed in the last second, since RN does not report screen reader focus. Without the rescue, web drops to body and TalkBack goes to the next node. Android hardware Tab skips the message.

Known gaps

  • Native hide does not restore focus (S23 jumps to Back). A restoreFocusRef prop can fix it in a follow-up.
  • No rescue for hardware keyboards on native: focus() on a View is a no-op on RN 0.88 and iOS never fires onFocus.
  • Real Safari not tested, WebKit and Firefox only via Playwright.
  • The message uses AnimatedText to get a host ref. A message that is a single Paper <Text variant> keeps bodyMedium on the outer line.
  • iOS still builds the announcement with extractText, until the children API question below is settled.

Media

web, only action removed, focus goes to the message:

web-after-focus-rescue-only-C.webm

web, hide with focus inside, focus goes back to the opener:

web-after-focus-return-on-hide.webm

TalkBack (emulator), C removed, cursor on A:
TalkBack cursor on Action A

@lukemorawski

Copy link
Copy Markdown
Contributor Author

@satya164 re your review: rebased, animation is on Reanimated now. rest is answered in the threads. extraction stays until the children API is decided.

@lukemorawski

Copy link
Copy Markdown
Contributor Author

@Doberjohn re the <Text> question: i'd go with a third option: message: string instead of children, plus an optional content slot rendered outside the Text and outside the live region.

<Banner visible message="Payment failed." actions={actions} />
<Banner visible message="Confirm your email" content={<TextInput />} />

cost: breaking, but mechanical, and old usage becomes a type error. rich inline text in the message goes (bold, links), content covers it.

fallback if you don't want to break it in 6.0: keep text children, add content and messageAccessibilityLabel.

which one? i'll do it in this PR.

also: does #5016 land before this one? both touch the Banner animation.

@jacekAtCK jacekAtCK self-assigned this Nov 23, 2026
Comment thread src/components/Banner.tsx Outdated
stop on android */}
{hasLiveRegion() ? (
<View style={styles.announcer}>
<Text {...region}>{announcement}</Text>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

a11y police: from reading the code this never fires on Android. RN Text doesn't map aria-live to accessibilityLiveRegion - only View does - and the test only checks the JS prop. Could we pass accessibilityLiveRegion={urgent ? 'assertive' : 'polite'} here and check that in the test?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed: the region is now a View with accessibilityLiveRegion={urgent ? 'assertive' : 'polite'} set directly, and aria-live still covers web. The tests check accessibilityLiveRegion. TalkBack on an API 33 emulator reads the message on show, with "Alert" after it when urgent is set.

@jacekAtCK jacekAtCK left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hiding part looks good :) I think that the Android live region looks like it never fires and a few cases aren't announced anymore. I've posted some comments

Comment thread src/components/Banner.tsx Outdated
const region: Pick<ViewProps, 'role' | 'aria-live'> = urgent
? { role: 'alert', 'aria-live': 'assertive' }
: { role: 'status', 'aria-live': 'polite' };
const message = extractText(children);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

extractText feeds the Android and web region too - not only iOS. So <Banner visible><Message /></Banner> is silent on every platform (checked with a quick test). Shall we keep that in mind for the children API decision?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, that settled it: message is a string prop now and feeds the region on every platform, so extractText is gone. A component goes in content, which isn't announced.

Comment thread src/components/Banner.tsx
}, [announce, visible]);

// labels are the natural key, but two actions can carry the same one
const actionKeys = visibleActions.map(({ label }, i) =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

label as key remounts the Button when its label changes - and the example does exactly that (Set custom theme → Set default theme). On web the rescue brings focus back but on native it looks like keyboard focus is lost. Could we keep index keys for the Button like main and use the labels only for the rescue?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed: the Button keys are indexes again, as on main, and the labels only tell the actions apart for the focus rescue. New test: a label change keeps the same Button, and its touchableRef is called once.

Comment thread docs/6.x/docs/guides/migration.md Outdated
</Banner>
```

The message is announced only when the banner goes from hidden to visible. Tests that use `getByRole('alert')` need `urgent`, or should find the message by text.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

are you sure that the test that use getbyrole need urgent? jest preset runs as ios and there the region isn't rendered at all - so getByRole('alert') finds nothing even with urgent.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You're right, it found nothing either way. The guide now says getByRole('alert') no longer finds the banner, with or without urgent, and to find the message by its text. A test checks that on iOS, Android and web.

@kachmashk kachmashk assigned kachmashk and unassigned jacekAtCK Dec 3, 2026
@Doberjohn

Copy link
Copy Markdown
Collaborator

@Doberjohn re the <Text> question: i'd go with a third option: message: string instead of children, plus an optional content slot rendered outside the Text and outside the live region.

} /> * fixes [TextInput loses focus inside Banner on iOS only #4178](https://github.com//issues/4178) by design, nothing non-text ends up inside a Text * iOS gets the announcement from `message`, so `extractText` and the `React.Children` walk go * text-only children alone don't solve that, `Hello {name}` is still an array * same move as [feat(dialog)!: replace children with title, content and actions props #5072](https://github.com//pull/5072) for Dialog

cost: breaking, but mechanical, and old usage becomes a type error. rich inline text in the message goes (bold, links), content covers it.

fallback if you don't want to break it in 6.0: keep text children, add content and messageAccessibilityLabel.

which one? i'll do it in this PR.

also: does #5016 land before this one? both touch the Banner animation.

@lukemorawski thanks for the proposal. Let's go with the first option, message: string plus a content slot, as #5072 did for Dialog.

@Doberjohn Doberjohn assigned Doberjohn and unassigned kachmashk Dec 4, 2026
- `message: string` replaces `children`, so the announcement reads the
  prop and no longer walks the children. `content` renders below the
  message, outside its Text and outside the live region.
- The live region is a View with `accessibilityLiveRegion`, so Android
  announces it. Its Text is added only while there is an announcement.
- Action buttons are keyed by index again, so a label change keeps the
  button and its focus. Labels are used only by the focus rescue, which
  now also follows an action whose button changed.
- The example gets a banner with a TextInput in `content`.
- The migration guide says what tests can query instead of
  `getByRole('alert')`.

BREAKING CHANGE: Banner takes its text as the `message` prop instead of children, and anything else as `content`.
A busy JS thread can take the next show before the report of a hide that
already finished on the UI thread. The report then unmounted the content
of the visible banner, leaving an empty spacer, and called
onHideAnimationFinished after the banner was back. Reports for a state
the banner has left are now dropped, for show and hide.
Copilot AI balanced review requested due to automatic review settings December 4, 2026 23:18
@Doberjohn Doberjohn changed the title feat(banner)!: make hidden content inert and fix live region semantics feat(banner)!: take text as message, make hidden content inert Dec 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Stale animation callbacks can prematurely unmount banner content or trigger duplicate completion events, while merged refs discard React 19 cleanup functions and risk resource leaks.

2 open issues

Review effort: Balanced

Comment thread src/components/Banner.tsx Resolved
Comment thread src/utils/mergeRefs.ts Resolved
@Doberjohn
Doberjohn dismissed JKobrynski’s stale review December 4, 2026 23:26

The children walk is gone with the message prop, and the other points were fixed earlier in this PR.

The previous fix only checked the current visible prop. After a hide, a
show and a hide, a late report from the first hide still passed: it
unmounted the content before the second hide ended and called
onHideAnimationFinished twice. Each visible change now gets a number,
and a report only counts for the change that started it.
React 19 callback refs can return a cleanup, and Reanimated's animated
components run it. mergeRefs dropped it, so a touchableRef passed to a
banner action was called with null on detach instead of running its
cleanup. mergeRefs now returns a cleanup that runs each ref's own and
clears the others.
Copilot AI balanced review requested due to automatic review settings December 5, 2026 07:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The banner can clip content when long actions exceed its constrained width, and removing a focused action on web can leave focus lost without falling back to the message.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/components/Banner.tsx Resolved
Comment thread src/components/Banner.tsx Resolved
On web, the focus rescue can pick a disabled action, or one without a
handler, and the browser won't focus either. Focus stayed on the body and
the tracker on an action that never had it, so a later change to that
action pulled focus back into the banner. The rescue now checks where
focus landed and otherwise focuses the message.
The inline layout follows the window width, so a narrow banner in a wide
window still put its actions beside the message. The actions row doesn't
shrink, so two long labels left the message a few pixels wide. The
message now keeps at least half the row, and actions that don't fit
beside it wrap onto a line of their own, at its end.
Copilot AI balanced review requested due to automatic review settings December 5, 2026 13:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because hidden banner content can retain or acquire native focus, hidden Android actions remain keyboard-activatable, and web action changes can drop focus.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(banner): make hidden content inert and fix live region semantics TextInput loses focus inside Banner on iOS only

8 participants