Skip to content

Commit cf50c37

Browse files
committed
fix alignment calendar icon
1 parent 375605f commit cf50c37

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

src/Date/DatePickerInput.shared.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type DatePickerInputProps = {
2121
endYear?: number
2222
onChangeText?: (text: string | undefined) => void
2323
inputEnabled?: boolean
24+
inputButton?: React.ReactNode
2425
} & Omit<
2526
React.ComponentProps<typeof TextInput>,
2627
'value' | 'onChange' | 'onChangeText' | 'inputMode'

src/Date/DatePickerInput.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react'
22

33
import { IconButton } from 'react-native-paper'
4-
import { StyleSheet } from 'react-native'
54
import DatePickerModal from './DatePickerModal'
65
import { useLatest } from '../utils'
76
import type { DatePickerInputProps } from './DatePickerInput.shared'
@@ -32,11 +31,10 @@ function DatePickerInput(
3231
<DatePickerInputWithoutModal
3332
ref={ref}
3433
{...rest}
35-
inputButtons={
34+
inputButton={
3635
withModal ? (
3736
<IconButton
3837
size={24}
39-
style={styles.calendarButton}
4038
icon={calendarIcon}
4139
disabled={rest.disabled}
4240
onPress={() => setVisible(true)}
@@ -79,8 +77,4 @@ function DatePickerInput(
7977
)
8078
}
8179

82-
const styles = StyleSheet.create({
83-
calendarButton: { position: 'absolute', right: 0, zIndex: 10 },
84-
})
85-
8680
export default React.forwardRef(DatePickerInput)

src/Date/DatePickerInputWithoutModal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function DatePickerInputWithoutModal(
2020
hideValidationErrors,
2121
onValidationError,
2222
modal,
23-
inputButtons,
23+
inputButton,
2424
saveLabel,
2525
saveLabelDisabled,
2626
uppercase,
@@ -76,6 +76,7 @@ function DatePickerInputWithoutModal(
7676
<View style={styles.root}>
7777
<View style={styles.inputContainer}>
7878
<TextInputWithMask
79+
inputButton={inputButton}
7980
{...rest}
8081
ref={ref}
8182
label={getLabel({
@@ -94,7 +95,7 @@ function DatePickerInputWithoutModal(
9495
error={(!!error && !hideValidationErrors) || !!hasError}
9596
style={[styles.input, style]}
9697
/>
97-
{inputButtons}
98+
{/* {inputButtons} */}
9899
</View>
99100
{error && !hideValidationErrors ? (
100101
<HelperText type="error" visible={!!error}>
@@ -136,6 +137,8 @@ function getLabel({
136137
const styles = StyleSheet.create({
137138
root: {
138139
flexGrow: 1,
140+
justifyContent: 'center',
141+
alignItems: 'flex-start',
139142
},
140143
inputContainer: {
141144
flexGrow: 1,

src/TextInputMask.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ function escapeForRegExp(value: string): string {
1313

1414
function TextInputWithMask(
1515
{
16+
inputButton,
1617
onChangeText,
1718
onChange,
1819
value,
1920
mask,
2021
disabled,
2122
...rest
22-
}: React.ComponentProps<typeof TextInput> & { mask: string; value: string },
23+
}: React.ComponentProps<typeof TextInput> & {
24+
mask: string
25+
value: string
26+
inputButton: React.ReactNode
27+
},
2328
ref: any
2429
) {
2530
const [controlledValue, setControlledValue] = React.useState<string>(
@@ -69,17 +74,20 @@ function TextInputWithMask(
6974
}, [value])
7075

7176
return (
72-
<TextInput
73-
ref={ref}
74-
{...rest}
75-
disabled={disabled}
76-
value={controlledValue}
77-
onChangeText={onInnerChange}
78-
onChange={(e) => {
79-
onChange && onChange(e)
80-
}}
81-
maxLength={10}
82-
/>
77+
<>
78+
<TextInput
79+
ref={ref}
80+
{...rest}
81+
disabled={disabled}
82+
value={controlledValue}
83+
onChangeText={onInnerChange}
84+
onChange={(e) => {
85+
onChange && onChange(e)
86+
}}
87+
maxLength={10}
88+
right={<TextInput.Icon icon={() => inputButton} />}
89+
/>
90+
</>
8391
)
8492
}
8593

0 commit comments

Comments
 (0)