Skip to content

Commit

Permalink
feat: don't hardcode header back test ID
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Now the back button test ID can be customized using headerBackTestID option
  • Loading branch information
satya164 committed Jan 15, 2021
1 parent 4954d6a commit 22a8afa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/stack/src/types.tsx
Expand Up @@ -147,6 +147,10 @@ export type StackHeaderOptions = {
* Accessibility label for the header back button.
*/
headerBackAccessibilityLabel?: string;
/**
* ID to locate this back button in tests.
*/
headerBackTestID?: string;
/**
* Title string used by the back button on iOS. Defaults to the previous scene's `headerTitle`.
* Use `headerBackTitleVisible: false` to hide it.
Expand Down Expand Up @@ -449,6 +453,10 @@ export type StackHeaderLeftButtonProps = {
* Accessibility label for the button for screen readers.
*/
accessibilityLabel?: string;
/**
* ID to locate this button in tests.
*/
testID?: string;
/**
* Style object for the button.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/stack/src/views/Header/HeaderBackButton.tsx
Expand Up @@ -30,6 +30,7 @@ export default function HeaderBackButton({
titleLayout,
truncatedLabel = 'Back',
accessibilityLabel = label && label !== 'Back' ? `${label}, back` : 'Go back',
testID,
style,
}: Props) {
const { dark, colors } = useTheme();
Expand Down Expand Up @@ -155,7 +156,7 @@ export default function HeaderBackButton({
accessible
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
testID="header-back"
testID={testID}
delayPressIn={0}
onPress={disabled ? undefined : handlePress}
pressColor={pressColorAndroid}
Expand Down
2 changes: 2 additions & 0 deletions packages/stack/src/views/Header/HeaderSegment.tsx
Expand Up @@ -163,6 +163,7 @@ export default function HeaderSegment(props: Props) {
headerTruncatedBackTitle: truncatedLabel,
headerPressColorAndroid: pressColorAndroid,
headerBackAccessibilityLabel: backAccessibilityLabel,
headerBackTestID: backTestID,
headerBackAllowFontScaling: backAllowFontScaling,
headerTitleAllowFontScaling: titleAllowFontScaling,
headerTitleStyle: customTitleStyle,
Expand Down Expand Up @@ -292,6 +293,7 @@ export default function HeaderSegment(props: Props) {
backImage,
pressColorAndroid,
accessibilityLabel: backAccessibilityLabel,
testID: backTestID,
allowFontScaling: backAllowFontScaling,
onPress: onGoBack,
labelVisible: headerBackTitleVisible,
Expand Down

0 comments on commit 22a8afa

Please sign in to comment.