Skip to content

Commit

Permalink
Merge pull request #40851 from bernhardoj/fix/40519-error-message-ove…
Browse files Browse the repository at this point in the history
…rlaps-with-other-field

Fix new room description field error message is overlapped by other fields highlight
  • Loading branch information
marcaaron authored Apr 24, 2024
2 parents 771449b + 21e7b1f commit e2fb9ac
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 30 deletions.
10 changes: 5 additions & 5 deletions src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function BaseTextInput(
disableKeyboard = false,
autoGrow = false,
autoGrowHeight = false,
maxAutoGrowHeight,
hideFocusedState = false,
maxLength = undefined,
hint = '',
Expand Down Expand Up @@ -245,14 +246,13 @@ function BaseTextInput(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const inputHelpText = errorText || hint;
const placeholderValue = !!prefixCharacter || isFocused || !hasLabel || (hasLabel && forceActiveLabel) ? placeholder : undefined;
const maxHeight = StyleSheet.flatten(containerStyles)?.maxHeight;
const newTextInputContainerStyles: StyleProp<ViewStyle> = StyleSheet.flatten([
styles.textInputContainer,
textInputContainerStyles,
autoGrow && StyleUtils.getWidthStyle(textInputWidth),
!hideFocusedState && isFocused && styles.borderColorFocus,
(!!hasError || !!errorText) && styles.borderColorDanger,
autoGrowHeight && {scrollPaddingTop: typeof maxHeight === 'number' ? 2 * maxHeight : undefined},
autoGrowHeight && {scrollPaddingTop: typeof maxAutoGrowHeight === 'number' ? 2 * maxAutoGrowHeight : undefined},
]);

return (
Expand All @@ -267,7 +267,7 @@ function BaseTextInput(
onLayout={onLayout}
accessibilityLabel={label}
style={[
autoGrowHeight && styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, typeof maxHeight === 'number' ? maxHeight : 0),
autoGrowHeight && styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0),
!isMultiline && styles.componentHeightLarge,
touchableInputWrapperStyle,
]}
Expand Down Expand Up @@ -346,7 +346,7 @@ function BaseTextInput(

// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
...(autoGrowHeight
? [StyleUtils.getAutoGrowHeightInputStyle(textInputHeight, typeof maxHeight === 'number' ? maxHeight : 0), styles.verticalAlignTop]
? [StyleUtils.getAutoGrowHeightInputStyle(textInputHeight, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0), styles.verticalAlignTop]
: []),
// Add disabled color theme when field is not editable.
inputProps.disabled && styles.textInputDisabled,
Expand Down Expand Up @@ -421,7 +421,7 @@ function BaseTextInput(
<Text
style={[
inputStyle,
autoGrowHeight && styles.autoGrowHeightHiddenInput(width ?? 0, typeof maxHeight === 'number' ? maxHeight : undefined),
autoGrowHeight && styles.autoGrowHeightHiddenInput(width ?? 0, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : undefined),
styles.hiddenElementOutsideOfWindow,
styles.visibilityHidden,
]}
Expand Down
10 changes: 5 additions & 5 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function BaseTextInput(
disableKeyboard = false,
autoGrow = false,
autoGrowHeight = false,
maxAutoGrowHeight,
hideFocusedState = false,
maxLength = undefined,
hint = '',
Expand Down Expand Up @@ -242,14 +243,13 @@ function BaseTextInput(
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const inputHelpText = errorText || hint;
const newPlaceholder = !!prefixCharacter || isFocused || !hasLabel || (hasLabel && forceActiveLabel) ? placeholder : undefined;
const maxHeight = StyleSheet.flatten(containerStyles).maxHeight;
const newTextInputContainerStyles: StyleProp<ViewStyle> = StyleSheet.flatten([
styles.textInputContainer,
textInputContainerStyles,
autoGrow && StyleUtils.getWidthStyle(textInputWidth),
!hideFocusedState && isFocused && styles.borderColorFocus,
(!!hasError || !!errorText) && styles.borderColorDanger,
autoGrowHeight && {scrollPaddingTop: typeof maxHeight === 'number' ? 2 * maxHeight : undefined},
autoGrowHeight && {scrollPaddingTop: typeof maxAutoGrowHeight === 'number' ? 2 * maxAutoGrowHeight : undefined},
]);
const isMultiline = multiline || autoGrowHeight;

Expand Down Expand Up @@ -287,7 +287,7 @@ function BaseTextInput(
// or if multiline is not supplied we calculate the textinput height, using onLayout.
onLayout={onLayout}
style={[
autoGrowHeight && styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, typeof maxHeight === 'number' ? maxHeight : 0),
autoGrowHeight && styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0),
!isMultiline && styles.componentHeightLarge,
touchableInputWrapperStyle,
]}
Expand Down Expand Up @@ -372,7 +372,7 @@ function BaseTextInput(

// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
...(autoGrowHeight
? [StyleUtils.getAutoGrowHeightInputStyle(textInputHeight, typeof maxHeight === 'number' ? maxHeight : 0), styles.verticalAlignTop]
? [StyleUtils.getAutoGrowHeightInputStyle(textInputHeight, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0), styles.verticalAlignTop]
: []),

// Add disabled color theme when field is not editable.
Expand Down Expand Up @@ -448,7 +448,7 @@ function BaseTextInput(
<Text
style={[
inputStyle,
autoGrowHeight && styles.autoGrowHeightHiddenInput(width ?? 0, typeof maxHeight === 'number' ? maxHeight : undefined),
autoGrowHeight && styles.autoGrowHeightHiddenInput(width ?? 0, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : undefined),
styles.hiddenElementOutsideOfWindow,
styles.visibilityHidden,
]}
Expand Down
5 changes: 5 additions & 0 deletions src/components/TextInput/BaseTextInput/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type CustomBaseTextInputProps = {
*/
autoGrowHeight?: boolean;

/**
* Maximum height for autoGrowHeight input
*/
maxAutoGrowHeight?: number;

/** Hide the focus styles on TextInput */
hideFocusedState?: boolean;

Expand Down
3 changes: 2 additions & 1 deletion src/pages/PrivateNotes/PrivateNotesEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import updateMultilineInputRange from '@libs/updateMultilineInputRange';
import type {WithReportAndPrivateNotesOrNotFoundProps} from '@pages/home/report/withReportAndPrivateNotesOrNotFound';
import withReportAndPrivateNotesOrNotFound from '@pages/home/report/withReportAndPrivateNotesOrNotFound';
import variables from '@styles/variables';
import * as ReportActions from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -151,7 +152,7 @@ function PrivateNotesEditPage({route, personalDetailsList, report}: PrivateNotes
maxLength={CONST.MAX_COMMENT_LENGTH}
autoCorrect={false}
autoGrowHeight
containerStyles={[styles.autoGrowHeightMultilineInput]}
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
defaultValue={privateNote}
value={privateNote}
onChangeText={(text: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/RoomDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ReportUtils from '@libs/ReportUtils';
import updateMultilineInputRange from '@libs/updateMultilineInputRange';
import variables from '@styles/variables';
import * as Report from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -84,6 +85,7 @@ function RoomDescriptionPage({report, policies}: RoomDescriptionPageProps) {
accessibilityLabel={translate('reportDescriptionPage.roomDescription')}
role={CONST.ROLE.PRESENTATION}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxLength={CONST.REPORT_DESCRIPTION.MAX_LENGTH}
ref={(el: BaseTextInputRef | null): void => {
if (!el) {
Expand All @@ -95,7 +97,6 @@ function RoomDescriptionPage({report, policies}: RoomDescriptionPageProps) {
value={description}
onChangeText={handleReportDescriptionChange}
autoCapitalize="none"
containerStyles={[styles.autoGrowHeightMultilineInput]}
/>
</View>
</FormProvider>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/iou/request/step/IOURequestStepDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import updateMultilineInputRange from '@libs/updateMultilineInputRange';
import variables from '@styles/variables';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -176,7 +177,7 @@ function IOURequestStepDescription({
updateMultilineInputRange(inputRef.current);
}}
autoGrowHeight
containerStyles={[styles.autoGrowHeightMultilineInput]}
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
shouldSubmitForm
isMarkdownEnabled
/>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/settings/ExitSurvey/ExitSurveyResponsePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function ExitSurveyResponsePage({draftResponse, route, navigation}: ExitSurveyRe
accessibilityLabel={translate(`exitSurvey.responsePlaceholder`)}
role={CONST.ROLE.PRESENTATION}
autoGrowHeight
maxAutoGrowHeight={responseInputMaxHeight}
maxLength={CONST.MAX_COMMENT_LENGTH}
ref={(el: AnimatedTextInputRef) => {
if (!el) {
Expand All @@ -136,7 +137,7 @@ function ExitSurveyResponsePage({draftResponse, route, navigation}: ExitSurveyRe
updateMultilineInputRange(el);
inputCallbackRef(el);
}}
containerStyles={[baseResponseInputContainerStyle, StyleUtils.getMaximumHeight(responseInputMaxHeight)]}
containerStyles={[baseResponseInputContainerStyle]}
shouldSaveDraft
/>
</>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/settings/Security/CloseAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ValidationUtils from '@libs/ValidationUtils';
import type {SettingsNavigatorParamList} from '@navigation/types';
import variables from '@styles/variables';
import * as CloseAccount from '@userActions/CloseAccount';
import * as User from '@userActions/User';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -101,10 +102,11 @@ function CloseAccountPage({session}: CloseAccountPageProps) {
InputComponent={TextInput}
inputID={INPUT_IDS.REASON_FOR_LEAVING}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
label={translate('closeAccountPage.enterMessageHere')}
aria-label={translate('closeAccountPage.enterMessageHere')}
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mt5, styles.autoGrowHeightMultilineInput]}
containerStyles={[styles.mt5]}
/>
<Text style={[styles.mt5]}>
{translate('closeAccountPage.enterDefaultContactToConfirm')} <Text style={[styles.textStrong]}>{userEmailOrPhone}</Text>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/tasks/NewTaskDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {NewTaskNavigatorParamList} from '@libs/Navigation/types';
import updateMultilineInputRange from '@libs/updateMultilineInputRange';
import variables from '@styles/variables';
import * as TaskActions from '@userActions/Task';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -87,8 +88,8 @@ function NewTaskDescriptionPage({task}: NewTaskDescriptionPageProps) {
updateMultilineInputRange(el);
}}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
shouldSubmitForm
containerStyles={styles.autoGrowHeightMultilineInput}
isMarkdownEnabled
/>
</View>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/tasks/NewTaskDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {NewTaskNavigatorParamList} from '@libs/Navigation/types';
import playSound, {SOUNDS} from '@libs/Sound';
import variables from '@styles/variables';
import * as TaskActions from '@userActions/Task';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -130,8 +131,8 @@ function NewTaskDetailsPage({task}: NewTaskDetailsPageProps) {
label={translate('newTaskPage.descriptionOptional')}
accessibilityLabel={translate('newTaskPage.descriptionOptional')}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
shouldSubmitForm
containerStyles={styles.autoGrowHeightMultilineInput}
defaultValue={parser.htmlToMarkdown(parser.replace(taskDescription))}
value={taskDescription}
onValueChange={setTaskDescription}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/tasks/TaskDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import updateMultilineInputRange from '@libs/updateMultilineInputRange';
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound';
import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound';
import variables from '@styles/variables';
import * as Task from '@userActions/Task';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -118,8 +119,8 @@ function TaskDescriptionPage({report, currentUserPersonalDetails}: TaskDescripti
updateMultilineInputRange(inputRef.current);
}}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
shouldSubmitForm
containerStyles={[styles.autoGrowHeightMultilineInput]}
isMarkdownEnabled
/>
</View>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceInviteMessagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import updateMultilineInputRange from '@libs/updateMultilineInputRange';
import type {SettingsNavigatorParamList} from '@navigation/types';
import variables from '@styles/variables';
import * as Link from '@userActions/Link';
import * as Policy from '@userActions/Policy';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -198,7 +199,7 @@ function WorkspaceInviteMessagePage({
autoCompleteType="off"
autoCorrect={false}
autoGrowHeight
containerStyles={[styles.autoGrowHeightMultilineInput]}
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
defaultValue={getDefaultWelcomeNote()}
value={welcomeNote}
onChangeText={(text: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli
accessibilityLabel={translate('reportDescriptionPage.roomDescriptionOptional')}
role={CONST.ROLE.PRESENTATION}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxLength={CONST.REPORT_DESCRIPTION.MAX_LENGTH}
autoCapitalize="none"
containerStyles={[styles.autoGrowHeightMultilineInput]}
shouldInterceptSwipe
/>
</View>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceProfileDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import updateMultilineInputRange from '@libs/updateMultilineInputRange';
import variables from '@styles/variables';
import * as Policy from '@userActions/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -99,11 +100,11 @@ function WorkspaceProfileDescriptionPage({policy}: Props) {
autoFocus
onChangeText={setDescription}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
isMarkdownEnabled
ref={(el: BaseTextInputRef | null): void => {
updateMultilineInputRange(el);
}}
containerStyles={[styles.autoGrowHeightMultilineInput]}
/>
</View>
</FormProvider>
Expand Down
7 changes: 2 additions & 5 deletions src/stories/TextInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {Meta, StoryFn} from '@storybook/react';
import React, {useState} from 'react';
import TextInput from '@components/TextInput';
import type {BaseTextInputProps} from '@components/TextInput/BaseTextInput/types';
import variables from '@styles/variables';

type TextInputStory = StoryFn<typeof TextInput>;

Expand Down Expand Up @@ -142,11 +143,7 @@ AutoGrowHeightInput.args = {
name: 'AutoGrowHeight',
placeholder: 'My placeholder text',
autoGrowHeight: true,
textInputContainerStyles: [
{
maxHeight: 115,
},
],
maxAutoGrowHeight: variables.textInputAutoGrowMaxHeight,
};

export default story;
Expand Down
4 changes: 0 additions & 4 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3275,10 +3275,6 @@ const styles = (theme: ThemeColors) =>
marginTop: 6,
},

autoGrowHeightMultilineInput: {
maxHeight: 115,
},

peopleRow: {
width: '100%',
flexDirection: 'row',
Expand Down
1 change: 1 addition & 0 deletions src/styles/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,5 @@ export default {
mushroomTopHatWidth: 138,
mushroomTopHatHeight: 128,
bankButtonMargin: 23,
textInputAutoGrowMaxHeight: 115,
} as const;

0 comments on commit e2fb9ac

Please sign in to comment.