Skip to content

Commit

Permalink
added comments and small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
syedsalehinipg committed Oct 26, 2023
1 parent 0ef9abb commit 0cfefbf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/Select/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function Select({
value = "",
variant = "outlined"
}) {
const valueIsValid = options.some(
// set value for select, when options is a key value pair the value will be in option.value otherwise option is the value
const setValue = options.some(
option => option.value === value || option === value
);

Expand All @@ -33,13 +34,14 @@ export default function Select({
margin={margin}
fullWidth
label={label}
value={valueIsValid ? value : ""}
value={setValue ? value : ""}
onChange={onChange}
disabled={disabled}
id={label}
helperText={helperText}
size={size}
>
{/* Render the options */}
{options.map(option => {
const value = option.value || option;
const key = option.key || option;
Expand Down Expand Up @@ -85,7 +87,7 @@ Select.propTypes = {
*/
onChange: PropTypes.func,
/**
* Array of options to display.
* Array of options to display. Each option can be a string, number, or an object with `key` and `value` properties.
*/
options: PropTypes.arrayOf(
PropTypes.oneOfType([
Expand Down
4 changes: 2 additions & 2 deletions src/Select/Select.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const KeyValueOptions = {
label: "Select an option",
margin: "normal",
options: [
{ key: "Option A", value: "Option A" },
{ key: "Option B", value: "Option B" }
{ key: "option-a", value: "Option A" },
{ key: "option-b", value: "Option B" }
],
required: true,
size: "medium",
Expand Down

0 comments on commit 0cfefbf

Please sign in to comment.