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

[Improvement] Introduce label props to statePicker & stateSelectorModal #24037

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions src/components/StatePicker/StateSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ const propTypes = {

/** Function to call when the user types in the search input */
setSearchValue: PropTypes.func.isRequired,

/** Label to display on field */
label: PropTypes.string,
};

const defaultProps = {
currentState: '',
onClose: () => {},
onStateSelected: () => {},
label: undefined,
};

function filterOptions(searchValue, data) {
Expand All @@ -42,7 +46,7 @@ function filterOptions(searchValue, data) {
return _.filter(data, (country) => country.text.toLowerCase().includes(searchValue.toLowerCase()));
}

function StateSelectorModal({currentState, isVisible, onClose, onStateSelected, searchValue, setSearchValue}) {
function StateSelectorModal({currentState, isVisible, onClose, onStateSelected, searchValue, setSearchValue, label}) {
const {translate} = useLocalize();

const countryStates = useMemo(
Expand All @@ -69,13 +73,13 @@ function StateSelectorModal({currentState, isVisible, onClose, onStateSelected,
useNativeDriver
>
<HeaderWithBackButton
title={translate('common.state')}
title={label || translate('common.state')}
shouldShowBackButton
onBackButtonPress={onClose}
/>
<SelectionListRadio
headerMessage={headerMessage}
textInputLabel={translate('common.state')}
textInputLabel={label || translate('common.state')}
textInputPlaceholder={translate('stateSelectorModal.placeholderText')}
textInputValue={searchValue}
sections={[{data: filteredData, indexOffset: 0}]}
Expand Down
9 changes: 7 additions & 2 deletions src/components/StatePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ const propTypes = {

/** A ref to forward to MenuItemWithTopDescription */
forwardedRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({current: PropTypes.instanceOf(React.Component)})]),

/** Label to display on field */
label: PropTypes.string,
};

const defaultProps = {
value: undefined,
forwardedRef: undefined,
errorText: '',
onInputChange: () => {},
label: undefined,
};

function StatePicker({value, errorText, onInputChange, forwardedRef}) {
function StatePicker({value, errorText, onInputChange, forwardedRef, label}) {
const {translate} = useLocalize();
const allStates = translate('allStates');
const [isPickerVisible, setIsPickerVisible] = useState(false);
Expand Down Expand Up @@ -61,7 +65,7 @@ function StatePicker({value, errorText, onInputChange, forwardedRef}) {
ref={forwardedRef}
shouldShowRightIcon
title={title}
description={translate('common.state')}
description={label || translate('common.state')}
descriptionTextStyle={descStyle}
onPress={showPickerModal}
/>
Expand All @@ -75,6 +79,7 @@ function StatePicker({value, errorText, onInputChange, forwardedRef}) {
onStateSelected={updateStateInput}
searchValue={searchValue}
setSearchValue={setSearchValue}
label={label}
/>
</View>
);
Expand Down
Loading