Skip to content

[slider] Fix interacting with TalkBack - #2578

Merged
mj12albert merged 11 commits into
mui:masterfrom
mj12albert:slider/fix-talkback
Aug 28, 2025
Merged

mj12albert merged 11 commits into
mui:masterfrom
mj12albert:slider/fix-talkback

Conversation

@mj12albert

@mj12albert mj12albert commented Aug 25, 2025 •

Copy link
Copy Markdown
Member

Demo: https://deploy-preview-2578--base-ui.netlify.app/react/components/slider

Breaking changes:

  • The input type="range" element receives focus and the thumb div is no longer focusable, focus styles targeting the thumb e.g. .Thumb:focus-visible should use .Thumb:has(:focus-visible) instead
  • The tabIndex prop is moved from Root to Thumb where it gets forwarded to the input
  • The thumb's render prop no longer contains the third inputProps argument, the input element is instead merged with children

Fixes #2575

@mj12albert mj12albert added the component: slider Changes related to the slider component. label Aug 25, 2025
@pkg-pr-new

pkg-pr-new Bot commented Aug 25, 2025 •

Copy link
Copy Markdown

vite-css-base-ui-example

pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/react@2578
pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/utils@2578

commit: fe5e58a

@mui-bot

mui-bot commented Aug 25, 2025 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui-components/react ▼-345B(-0.11%) ▼-175B(-0.18%)

Details of bundle changes

Generated by 🚫 dangerJS against fe5e58a

@netlify

netlify Bot commented Aug 25, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit fe5e58a
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/68afd32c7ca6820008e04d94
😎 Deploy Preview https://deploy-preview-2578--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@oliviertassinari

oliviertassinari commented Aug 25, 2025 •

Copy link
Copy Markdown
Member

This work on my end with TalkBack 👍

@oliviertassinari oliviertassinari added accessibility a11y breaking change Introduces changes that are not backward compatible. labels Aug 25, 2025
@oliviertassinari

oliviertassinari commented Aug 25, 2025 •

Copy link
Copy Markdown
Member

To avoid future regressions, maybe we can add a test after

describe('<Radio />', () => {
where tabbing should land on an input type range, and explain why it's done this way (not sure we actually need the e2e infrastructure for this test, maybe a simple unit test would support it).

@mj12albert
mj12albert force-pushed the slider/fix-talkback branch 3 times, most recently from 13c2bf7 to 038f96e Compare August 26, 2025 09:21
@oliviertassinari oliviertassinari added the type: regression A bug, but worse, it used to behave as expected. label Aug 26, 2025
@mj12albert
mj12albert force-pushed the slider/fix-talkback branch from 3977562 to af12bde Compare August 26, 2025 14:40
@mj12albert
mj12albert force-pushed the slider/fix-talkback branch from 027bcca to e2b789b Compare August 26, 2025 14:46
@mj12albert
mj12albert marked this pull request as ready for review August 26, 2025 14:53
// See:
// - https://issues.chromium.org/issues/40816094
// - https://github.com/mui/material-ui/issues/23506
describe('events', () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

where tabbing should land on an input type range, and explain why it's done this way (not sure we actually need the e2e infrastructure for this test, maybe a simple unit test would support it)

I've added a bunch of tests here around this @oliviertassinari

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.

Yeah, ok, makes sense to me 👍

@atomiks

atomiks commented Aug 26, 2025 •

Copy link
Copy Markdown
Contributor

When pressing the thumb with the pointer on first load, I see the :focus-visible outline, or is this fixed in a different PR?

@mj12albert

Copy link
Copy Markdown
Member Author

When pressing the thumb with the pointer on first load, I see the :focus-visible outline, or is this fixed in a different PR?

Yeah I made a different branch to tweak this so the Talkback regression can get merged sooner ~

@oliviertassinari oliviertassinari left a comment

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.

When pressing the thumb with the pointer on first load, I see the :focus-visible outline, or is this fixed in a different PR?

I guess it's w3c/csswg-drafts#5885. Is this even solvable? It seems to have been done on purpose by Chromium and Firefox.

// See:
// - https://issues.chromium.org/issues/40816094
// - https://github.com/mui/material-ui/issues/23506
describe('events', () => {

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.

Yeah, ok, makes sense to me 👍

@oliviertassinari oliviertassinari changed the title [slider] Fix interacting with Talkback [slider] Fix interacting with TalkBack Aug 26, 2025
Co-authored-by: Olivier Tassinari <[email protected]>
Signed-off-by: Albert Yu <[email protected]>
@mj12albert

Copy link
Copy Markdown
Member Author

I guess it's w3c/csswg-drafts#5885. Is this even solvable?

It's related and indeed intentional on the browser's part, if we give up Firefox support for now (it's a bug on their side) it seems to be solvable: #2584

@oliviertassinari

oliviertassinari commented Aug 27, 2025 •

Copy link
Copy Markdown
Member

It's related and indeed intentional on the browser's part, if we give up Firefox support for now (it's a bug on their side) it seems to be solvable: #2584

@mj12albert Right, ok, because

thumbRefs.current?.[thumbIndex]
?.querySelector<HTMLInputElement>('input[type="range"]')
?.focus();

But then I don't understand #2584, there are a lot of lines of code (on top of this PR). Why can't we fix #2578 (comment) with:

diff --git a/packages/react/src/slider/control/SliderControl.tsx b/packages/react/src/slider/control/SliderControl.tsx
index caa2a0be..0f0ab451 100644
--- a/packages/react/src/slider/control/SliderControl.tsx
+++ b/packages/react/src/slider/control/SliderControl.tsx
@@ -226,7 +226,7 @@ export const SliderControl = React.forwardRef(function SliderControl(
       setActive(thumbIndex);
       thumbRefs.current?.[thumbIndex]
         ?.querySelector<HTMLInputElement>('input[type="range"]')
-        ?.focus();
+        ?.focus({ focusVisible: false });
     }
   });

If the interaction is a keyboard, it will focus the right element, so focus() won't be called.

@mj12albert

Copy link
Copy Markdown
Member Author

Why can't we fix #2578 (comment) with:

The focusVisible option doesn't have good browser support (caniuse), and didn't seem to work very consistently in the supported ones

@LukasTy LukasTy left a comment

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.

Looks great, nice work! 👍
The component now works with screen readers (the current released version is completely broken on NVDA (with Firefox) - kind of an industry standard)

I take it the focusing is handled in the separate PR, since that's the only regression I can see. 🤔

@oliviertassinari

oliviertassinari commented Aug 27, 2025 •

Copy link
Copy Markdown
Member

Option doesn't have good browser support (caniuse)

@mj12albert Right, it only works with Safari and Firefox.

didn't seem to work very consistently in the supported ones

What are those issues? I couldn't notice problems.

Two thoughts:

  1. We could sleep on this. Add focusVisible: false and wait. The problem itself is not that important. What's the likelihood that someone's first focus interaction on a page is a slider? As a user, do you want the extra bundle size & complexity to fix this? Maybe not.
  2. If we don't do 1. let's have a clear step to remove all the unnecessary logic once supported. I have upvoted https://issues.chromium.org/issues/40834435.

@mj12albert
mj12albert force-pushed the slider/fix-talkback branch from 5ac730d to ba7fc72 Compare August 27, 2025 15:32
@mj12albert

Copy link
Copy Markdown
Member Author

What are those issues?

I meant that it didn't work when applied to this scenario, something like:

<div
  id="thumb"
  onPointerDown={() => {
    requestAnimationFrame(() => {
      inputRef.current?.focus({ focusVisible: false });
    });
  }}
>
  <input
    ref={inputRef}
    style={visuallyHidden}
    type="range"
    onKeyDown={() => {
      requestAnimationFrame(() => {
        inputRef.current?.focus({ focusVisible: true });
      });
    }}
  />
</div>

Though if it had wider support it could indeed be used for a simpler fix here

@mj12albert
mj12albert merged commit 40308ba into mui:master Aug 28, 2025
@mj12albert
mj12albert deleted the slider/fix-talkback branch August 28, 2025 04:08
@oliviertassinari

oliviertassinari commented Aug 28, 2025 •

Copy link
Copy Markdown
Member

I meant that it didn't work when applied to this scenario, something like:

@mj12albert Ok, let's wait then. Issue created #2592 for the future.

atomiks pushed a commit to atomiks/base-ui that referenced this pull request Sep 10, 2025
Signed-off-by: Albert Yu <[email protected]>
Co-authored-by: Olivier Tassinari <[email protected]>
@coderabbitai coderabbitai Bot mentioned this pull request Aug 26, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y breaking change Introduces changes that are not backward compatible. component: slider Changes related to the slider component. type: regression A bug, but worse, it used to behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[slider] Broken TalkBack support

5 participants