Skip to content

Commit 9e6a86a

Browse files
feat: add testId to picker items (#498)
Co-authored-by: Michael Lefkowitz <1746853+lfkwtz@users.noreply.github.com>
1 parent d8895ff commit 9e6a86a

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const Dropdown = () => {
6464
| Name | Description | Details |
6565
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
6666
| `onValueChange` | Callback which returns `value, index` | **required**<br>function |
67-
| `items` | The items for the component to render<br> - Each item should be in the following format:<br>`{label: 'Orange', value: 'orange', key: 'orange', color: 'orange', inputLabel: 'Orange!'}`<br>- `label` and `value` are required<br>- `key`, `color`, and `inputLabel` are optional<br>- `key` will be set to equal `label` if not included<br>- `value` can be any data type<br>- If `inputLabel` exists, the TextInput will display that value instead of the `label` | **required**<br>array |
67+
| `items` | The items for the component to render<br> - Each item should be in the following format:<br>`{label: 'Orange', value: 'orange', key: 'orange', color: 'orange', inputLabel: 'Orange!', testID: 'e2e-orange'}`<br>- `label` and `value` are required<br>- `key`, `color`, and `inputLabel` are optional<br>- `key` will be set to equal `label` if not included<br>- `value` can be any data type<br>- If `inputLabel` exists, the TextInput will display that value instead of the `label`<br>- `testID` will be used in e2e tests to locate the options | **required**<br>array |
6868
| `placeholder` | - An override for the default placeholder object with a label of `Select an item...` and a value of `null`<br>- An empty object can be used if you'd like to disable the placeholder entirely | object |
6969
| `disabled` | Disables interaction with the component | boolean |
7070
| `value` | Will attempt to locate a matching item from the `items` array by checking each item's `value` property. If found, it will update the component to show that item as selected. If the value is not found, it will default to the first item. | any |

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class RNPickerSelect extends PureComponent {
1212
PropTypes.shape({
1313
label: PropTypes.string.isRequired,
1414
value: PropTypes.any.isRequired,
15+
testID: PropTypes.string,
1516
inputLabel: PropTypes.string,
1617
key: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
1718
color: PropTypes.string,
@@ -278,6 +279,7 @@ export default class RNPickerSelect extends PureComponent {
278279
value={item.value}
279280
key={item.key || item.label}
280281
color={item.color || defaultItemColor}
282+
testID={item.testID}
281283
/>
282284
);
283285
});

0 commit comments

Comments
 (0)