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

TextField - ClearButton - fix right margin #3482

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions src/components/textField/ClearButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const TIMING_CONFIG = {
easing: Easing.bezier(0.33, 1, 0.68, 1)
};

const ClearButton = ({testID, onClear, onChangeText}: Pick<TextFieldProps, 'onClear' | 'testID' | 'onChangeText'>) => {
const ClearButton = ({
testID,
onClear,
onChangeText,
preset
}: Pick<TextFieldProps, 'onClear' | 'testID' | 'onChangeText' | 'preset'>) => {
const {hasValue} = useContext(FieldContext);
const animatedValue = useSharedValue(hasValue ? VISIBLE_POSITION : NON_VISIBLE_POSITION);
const animatedOpacity = useSharedValue(hasValue ? 1 : 0);
Expand All @@ -29,7 +34,8 @@ const ClearButton = ({testID, onClear, onChangeText}: Pick<TextFieldProps, 'onCl
};
});

const style = useMemo(() => [styles.container, animatedStyle], [animatedStyle]);
const style = useMemo(() => [styles.container, preset === 'underline' && {marginRight: Spacings.s3}, animatedStyle],
[animatedStyle, preset]);

const animate = useCallback(() => {
const toValue = hasValue ? VISIBLE_POSITION : NON_VISIBLE_POSITION;
Expand Down Expand Up @@ -65,7 +71,7 @@ const ClearButton = ({testID, onClear, onChangeText}: Pick<TextFieldProps, 'onCl

const styles = StyleSheet.create({
container: {
marginHorizontal: Spacings.s3
marginLeft: Spacings.s3
},
clearIcon: {
tintColor: Colors.$textNeutralLight
Expand Down
7 changes: 6 additions & 1 deletion src/components/textField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ const TextField = (props: InternalTextFieldProps) => {
</View>
)}
{showClearButton && (
<ClearButton onClear={onClear} testID={`${props.testID}.clearButton`} onChangeText={onChangeText}/>
<ClearButton
onClear={onClear}
testID={`${props.testID}.clearButton`}
onChangeText={onChangeText}
preset={props.preset}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The ClearButton component shouldn't be aware of the preset. I think we should pass 'style' instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

/>
)}
{trailingAccessory}
{/* </View> */}
Expand Down