From 467df4085247b240de9ba7794a3c761b2331713e Mon Sep 17 00:00:00 2001 From: irekrog Date: Fri, 19 Nov 2021 14:03:54 +0100 Subject: [PATCH] fix: clear option button --- src/components/select-control/index.tsx | 21 +++++++++++++++-- src/components/select/index.tsx | 6 +++++ src/types/index.ts | 30 ++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/components/select-control/index.tsx b/src/components/select-control/index.tsx index cd39f5a5..ebdddb46 100644 --- a/src/components/select-control/index.tsx +++ b/src/components/select-control/index.tsx @@ -32,6 +32,9 @@ type FromSelectComponentProps = Pick< | 'selectControlOpenDropdownA11yLabel' | 'selectControlCloseDropdownA11yLabel' | 'selectControlTextStyle' + | 'selectControlClearOptionButtonStyle' + | 'selectControlClearOptionButtonHitSlop' + | 'selectControlClearOptionImageStyle' >; type SelectControlProps = OptionalToRequired< @@ -57,6 +60,9 @@ export const SelectControl = forwardRef( disabled, placeholderText, selectControlDisabledStyle, + selectControlClearOptionButtonHitSlop, + selectControlClearOptionButtonStyle, + selectControlClearOptionImageStyle, selectControlClearOptionA11yLabel, selectControlOpenDropdownA11yLabel, selectControlCloseDropdownA11yLabel, @@ -117,10 +123,16 @@ export const SelectControl = forwardRef( selectControlClearOptionA11yLabel || 'Clear a chosen option' } disabled={disabled} - onPress={onPressRemove}> + hitSlop={ + selectControlClearOptionButtonHitSlop + ? selectControlClearOptionButtonHitSlop + : { right: 3, left: 3 } + } + onPress={onPressRemove} + style={[styles.xIconWrapper, selectControlClearOptionButtonStyle]}> )} @@ -151,6 +163,7 @@ type Styles = { arrowIconOpened: ImageStyle; arrowIconClosed: ImageStyle; xIcon: ImageStyle; + xIconWrapper: ViewStyle; }; const styles = StyleSheet.create({ @@ -195,6 +208,10 @@ const styles = StyleSheet.create({ height: 25, zIndex: -1, }, + xIconWrapper: { + height: '100%', + justifyContent: 'center', + }, xIcon: { width: 20, height: 20, diff --git a/src/components/select/index.tsx b/src/components/select/index.tsx index c4bd05c5..d78f2687 100644 --- a/src/components/select/index.tsx +++ b/src/components/select/index.tsx @@ -41,6 +41,9 @@ export const Select = forwardRef((props: SelectProps, ref: ForwardedRef; + /** + * Style of clear option button + * + * @category Styles + */ + selectControlClearOptionButtonStyle?: StyleProp; + + /** + * Hit Slop for clear option button + * + * @category Styles + */ + selectControlClearOptionButtonHitSlop?: Insets; + + /** + * Style of clear option image + * + * @category Styles + */ + selectControlClearOptionImageStyle?: ImageStyle; + /** * Style of container select control *