Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/30842 - Add accessibilityState prop in slider #31145

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Libraries/Components/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
import type {ColorValue} from '../../StyleSheet/StyleSheet';
import type {ViewProps} from '../View/ViewPropTypes';
import type {SyntheticEvent} from '../../Types/CoreEventTypes';
import type {AccessibilityState} from './View/ViewAccessibility';

type Event = SyntheticEvent<
$ReadOnly<{|
Expand Down Expand Up @@ -130,6 +131,12 @@ type Props = $ReadOnly<{|
* Used to locate this view in UI automation tests.
*/
testID?: ?string,

/**
Indicates to accessibility services that UI Component is in a specific State.
*/
accessibilityState?: ?AccessibilityState,

|}>;

/**
Expand Down Expand Up @@ -197,6 +204,7 @@ const Slider = (
forwardedRef?: ?React.Ref<typeof SliderNativeComponent>,
) => {
const style = StyleSheet.compose(styles.slider, props.style);
const accessibilityState = props.accessibilityState || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be an empty object if no props.accessibilityState? It seems like SliderNativeComponent allows for null value for accessibilityState prop. In this approach you'd be a creating a non-used new object every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was wondering too, so should we just omit the empty object since props.accessibilityState would return null if its empty

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea we can directly pass the prop to the native component.


const {
disabled = false,
Expand Down Expand Up @@ -233,6 +241,7 @@ const Slider = (
<SliderNativeComponent
{...localProps}
// TODO: Reconcile these across the two platforms.
accessibilityState={accessibilityState}
enabled={!disabled}
disabled={disabled}
maximumValue={maximumValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
TouchableWithoutFeedback,
Alert,
StyleSheet,
Slider,
Platform,
} = require('react-native');

Expand Down Expand Up @@ -605,6 +606,15 @@ class AccessibilityActionsExample extends React.Component {
</View>
</TouchableWithoutFeedback>
</RNTesterBlock>

<RNTesterBlock title="Fake slider example">
<SliderNativeComponent
maximumValue={maximumValue}
minimumValue={minimumValue}
onPress={() => Alert.alert('Alert has been moved')}
/>
<Text>Slider</Text>
</RNTesterBlock>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is my first time trying to add a test/example, woud I need to set the accessibilityState={{disabled: true}} as initially ? and how would i set it later on like when the slider is used should I alert that the state has changed

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the original issue is that the Slider component does not announce its selection on focus. So you'd want to render a Slider component here .. I'm not sure if there's a callback for an onFocus here. But at least with Talkback/VoiceOver on we'd want to confirm that the Slider state is being announced. Not sure the best way to illustrate that in the example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh maybe I can ask @fabriziobertoglio1987 to assist us here

Copy link
Contributor

Choose a reason for hiding this comment

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

@sladyn98 Here are the docs for the Slider component 🙏 https://reactnative.dev/docs/next/slider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added an example here, how do I get i set the accessibility State here ? like it does not have a property pertaining to that

Copy link
Contributor

Choose a reason for hiding this comment

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

@sladyn98 I'm not sure I understand your question. I think you want to render something like:

<Slider
  maximumValue={maximumValue}
  minimumValue={minimumValue}
  onSlidingComplete={onSlidingComplete}
  value={value}
  accessibilityState={{disabled: true}} // or whatever accessibilityState you'd want to pass
/>

and then verify with TalkBack that the slider is respecting the accessibilityState passed. The one I'm most familiar with is disability but there are others: https://reactnative.dev/docs/accessibility#accessibilitystate

Some of them may not make sense on the Slider component like busy/expanded but maybe you could experiment and add a comment about what is expected?

Copy link
Contributor

Choose a reason for hiding this comment

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

Whoops sorry about the delay, forgot to hit submit!

</View>
);
}
Expand Down