Skip to content

Commit

Permalink
Fixed clear car
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixH committed Nov 19, 2021
1 parent bc04ee5 commit a114342
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/components/modal/ModalSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Props<T> extends BaseProps {
// Render a generic item when nothing is selected
renderItemPlaceholder?: () => React.ReactElement;
// Whether or not to display the button to clear the input
canClearInput?: boolean;
clearable?: boolean;
selectionMode: ItemSelectionMode;
onItemsSelected: (selectedItems: T[]) => void;
defaultItemLoading?: boolean;
Expand Down Expand Up @@ -137,7 +137,7 @@ export default class ModalSelect<T extends ListItem> extends React.Component<Pro
}

private renderButton(style: any) {
const { defaultItemLoading, renderNoItem, renderItem, renderItemPlaceholder, openable, disabled, canClearInput, defaultItem } = this.props;
const { defaultItemLoading, renderNoItem, renderItem, renderItemPlaceholder, openable, disabled, clearable, defaultItem } = this.props;
const { selectedItems, noneSelected } = this.state;
const listItemCommonStyle = computeListItemCommonStyle();

Expand All @@ -149,27 +149,28 @@ export default class ModalSelect<T extends ListItem> extends React.Component<Pro
</View>
);
}
if ((defaultItem || selectedItems[0]) && !noneSelected) {
if ((selectedItems[0] || defaultItem)) {
return (
<TouchableOpacity
disabled={disabled || !openable}
onPress={() => this.setState({ isVisible: true })}
style={[style.itemContainer, disabled && style.buttonDisabled]}>
{canClearInput && (
{clearable && (
<TouchableOpacity style={style.clearContainer} onPress={() => this.resetInput(true)}>
<Text style={{textAlign: 'right', color: commonColors.primary}}>{I18n.t('cars.clearCar')}</Text>
</TouchableOpacity>
)}
{renderItem?.(selectedItems[0] ?? defaultItem)}
</TouchableOpacity>
);
} else if (renderItemPlaceholder && noneSelected !== false) {
} if (renderItemPlaceholder && (noneSelected || !renderNoItem)) {
return (
<TouchableOpacity onPress={() => this.setState({ isVisible: true })} style={style.itemContainer}>
{renderItemPlaceholder?.()}
</TouchableOpacity>
);
} else {
}
else {
return <View style={style.itemContainer}>{renderNoItem?.()}</View>;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ export default class ChargingStationConnectorDetails extends BaseAutoRefreshScre
disabled={disabled}
openable={true}
renderNoItem={this.renderNoCar.bind(this)}
canClearInput={true}
clearable={true}
renderItem={() => <CarComponent car={selectedCar} navigation={navigation} />}
ref={this.carModalRef}
defaultItem={selectedCar}
Expand Down

0 comments on commit a114342

Please sign in to comment.