Skip to content

Commit 3031e8a

Browse files
authored
Merge pull request #16449 from allroundexperts/fix-15877
fix-15877: add disabled state styles to Picker
2 parents dfb2222 + 3f7524b commit 3031e8a

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

src/components/Picker/Picker.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ const propTypes = {
7878

7979
/** Additional events passed to the core Picker for specific platforms such as web */
8080
additionalPickerEvents: PropTypes.func,
81+
82+
/** Hint text that appears below the picker */
83+
hintText: PropTypes.string,
8184
};
8285

8386
const defaultProps = {
8487
label: '',
8588
isDisabled: false,
8689
errorText: '',
90+
hintText: '',
8791
containerStyles: [],
8892
backgroundColor: undefined,
8993
inputID: undefined,
@@ -172,6 +176,27 @@ class Picker extends PureComponent {
172176
render() {
173177
const hasError = !_.isEmpty(this.props.errorText);
174178

179+
if (this.props.isDisabled) {
180+
return (
181+
<View>
182+
{this.props.label && (
183+
<Text style={[styles.textLabelSupporting, styles.mb1]} numberOfLines={1}>
184+
{this.props.label}
185+
</Text>
186+
)}
187+
<Text numberOfLines={1}>
188+
{this.props.value}
189+
</Text>
190+
{this.props.hintText
191+
&& (
192+
<Text style={[styles.textLabel, styles.colorMuted, styles.mt2]}>
193+
{this.props.hintText}
194+
</Text>
195+
)}
196+
</View>
197+
);
198+
}
199+
175200
return (
176201
<>
177202
<View
@@ -230,6 +255,12 @@ class Picker extends PureComponent {
230255
/>
231256
</View>
232257
<FormHelpMessage message={this.props.errorText} />
258+
{this.props.hintText
259+
&& (
260+
<Text style={[styles.textLabel, styles.colorMuted, styles.mt2]}>
261+
{this.props.hintText}
262+
</Text>
263+
)}
233264
</>
234265
);
235266
}

src/languages/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ export default {
10311031
nameIsRequiredError: 'You need to define a name for your workspace.',
10321032
currencyInputLabel: 'Default currency',
10331033
currencyInputHelpText: 'All expenses on this workspace will be converted to this currency.',
1034+
currencyInputDisabledText: 'The default currency can\'t be changed because this workspace is linked to a USD bank account.',
10341035
save: 'Save',
10351036
genericFailureMessage: 'An error occurred updating the workspace, please try again.',
10361037
avatarUploadFailureMessage: 'An error occurred uploading the avatar, please try again.',

src/languages/es.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ export default {
10321032
nameIsRequiredError: 'Debes definir un nombre para tu espacio de trabajo.',
10331033
currencyInputLabel: 'Moneda por defecto',
10341034
currencyInputHelpText: 'Todas los gastos en este espacio de trabajo serán convertidos a esta moneda.',
1035+
currencyInputDisabledText: 'La moneda predeterminada no se puede cambiar porque este espacio de trabajo está vinculado a una cuenta bancaria en USD.',
10351036
save: 'Guardar',
10361037
genericFailureMessage: 'Se produjo un error al guardar el espacio de trabajo. Por favor, inténtalo de nuevo.',
10371038
avatarUploadFailureMessage: 'No se pudo subir el avatar. Por favor, inténtalo de nuevo.',

src/pages/workspace/WorkspaceSettingsPage.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import lodashGet from 'lodash/get';
77
import ONYXKEYS from '../../ONYXKEYS';
88
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
99
import styles from '../../styles/styles';
10-
import Text from '../../components/Text';
1110
import compose from '../../libs/compose';
1211
import * as Policy from '../../libs/actions/Policy';
1312
import * as Expensicons from '../../components/Icon/Expensicons';
@@ -143,11 +142,13 @@ class WorkspaceSettingsPage extends React.Component {
143142
items={this.getCurrencyItems()}
144143
isDisabled={hasVBA}
145144
defaultValue={this.props.policy.outputCurrency}
145+
hintText={
146+
hasVBA
147+
? this.props.translate('workspace.editor.currencyInputDisabledText')
148+
: this.props.translate('workspace.editor.currencyInputHelpText')
149+
}
146150
/>
147151
</View>
148-
<Text style={[styles.textLabel, styles.colorMuted, styles.mt2]}>
149-
{this.props.translate('workspace.editor.currencyInputHelpText')}
150-
</Text>
151152
</OfflineWithFeedback>
152153
</Form>
153154
)}

src/stories/Picker.stories.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const Default = Template.bind({});
3131
Default.args = {
3232
label: 'Default picker',
3333
name: 'Default',
34+
hintText: 'Default hint text',
3435
items: [
3536
{
3637
label: 'Orange',
@@ -48,6 +49,7 @@ PickerWithValue.args = {
4849
label: 'Picker with defined value',
4950
name: 'Picker with defined value',
5051
value: 'apple',
52+
hintText: 'Picker with hint text',
5153
items: [
5254
{
5355
label: 'Orange',
@@ -64,6 +66,7 @@ const ErrorStory = Template.bind({});
6466
ErrorStory.args = {
6567
label: 'Picker with error',
6668
name: 'PickerWithError',
69+
hintText: 'Picker hint text',
6770
errorText: 'This field has an error.',
6871
items: [
6972
{
@@ -81,7 +84,9 @@ const Disabled = Template.bind({});
8184
Disabled.args = {
8285
label: 'Picker disabled',
8386
name: 'Disabled',
87+
value: 'orange',
8488
isDisabled: true,
89+
hintText: 'Picker hint text',
8590
items: [
8691
{
8792
label: 'Orange',

0 commit comments

Comments
 (0)