agroptima-design-system 0.34.9 → 0.34.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agroptima-design-system",
3
- "version": "0.34.9",
3
+ "version": "0.34.10",
4
4
  "scripts": {
5
5
  "dev": "npm run storybook",
6
6
  "storybook": "storybook dev -p 6006 --ci",
@@ -29,6 +29,7 @@ export interface SelectProps extends InputPropsWithoutOnChange {
29
29
  onChange?: (value: string) => void
30
30
  isSearchable?: boolean
31
31
  searchLabel?: string
32
+ isClereable?: boolean
32
33
  }
33
34
 
34
35
  const EMPTY_OPTION = { id: '', label: '' }
@@ -50,11 +51,12 @@ export function Select({
50
51
  defaultValue,
51
52
  isSearchable = false,
52
53
  searchLabel = 'Search',
54
+ isClereable = true,
53
55
  ...props
54
56
  }: SelectProps): React.JSX.Element {
55
57
  const { isOpen, close, toggle } = useOpen()
56
58
  const defaultOption =
57
- options.find((option) => option.id === defaultValue) || EMPTY_OPTION
59
+ options.find((option) => option.id === defaultValue) || (isClereable ? EMPTY_OPTION : options[0])
58
60
  const [selectedOption, setSelectedOption] = useState<Option>(defaultOption)
59
61
  const isEmpty = selectedOption.id === EMPTY_OPTION.id
60
62
  const isInvalid = Boolean(errors?.length)
@@ -98,6 +100,7 @@ export function Select({
98
100
  onClick={toggle}
99
101
  onClear={handleClear}
100
102
  isEmpty={isEmpty}
103
+ isClereable={isClereable}
101
104
  >
102
105
  {selectedOption.label || placeholder}
103
106
  </SelectTrigger>
@@ -12,6 +12,7 @@ export interface SelectTriggerProps {
12
12
  isEmpty: boolean
13
13
  onClick: () => void
14
14
  onClear: (event: React.MouseEvent) => void
15
+ isClereable?: boolean
15
16
  children: React.ReactNode
16
17
  }
17
18
 
@@ -24,6 +25,7 @@ export function SelectTrigger({
24
25
  isOpen,
25
26
  onClick,
26
27
  onClear,
28
+ isClereable=true,
27
29
  isEmpty,
28
30
  children,
29
31
  }: SelectTriggerProps) {
@@ -54,7 +56,7 @@ export function SelectTrigger({
54
56
  visible={isEmpty}
55
57
  />
56
58
  </button>
57
- <IconButton
59
+ {isClereable && (<IconButton
58
60
  type="button"
59
61
  size="3"
60
62
  icon="Close"
@@ -62,7 +64,7 @@ export function SelectTrigger({
62
64
  accessibilityLabel="clear"
63
65
  onClick={handleClear}
64
66
  visible={!isEmpty}
65
- />
67
+ />)}
66
68
  </div>
67
69
  )
68
70
  }
@@ -82,6 +82,7 @@ export const Primary: Story = {
82
82
  accessibilityLabel: 'Select your favourite gaming system options',
83
83
  hideLabel: false,
84
84
  isSearchable: false,
85
+ isClereable: true,
85
86
  placeholder: 'Select your favourite gaming system...',
86
87
  options: [
87
88
  { id: '1', label: 'Nintendo Switch' },
@@ -120,6 +121,7 @@ export const PrimaryWithSelectedOptions: Story = {
120
121
  hideLabel: false,
121
122
  placeholder: 'Select your favourite gaming system...',
122
123
  isSearchable: false,
124
+ isClereable: true,
123
125
  options: [
124
126
  { id: '1', label: 'Nintendo Switch' },
125
127
  { id: '2', label: 'PlayStation 5' },
@@ -142,6 +144,7 @@ export const PrimaryWithErrors: Story = {
142
144
  hideLabel: false,
143
145
  placeholder: 'Select your favourite gaming system...',
144
146
  isSearchable: false,
147
+ isClereable: true,
145
148
  options: [
146
149
  { id: '1', label: 'Nintendo Switch' },
147
150
  { id: '2', label: 'PlayStation 5' },
@@ -187,6 +190,7 @@ export const PrimaryWithSearch: Story = {
187
190
  id: 'select-videogames',
188
191
  onChange: (optionId) => console.log('onChange optionId:', optionId),
189
192
  isSearchable: true,
193
+ isClereable: true,
190
194
  searchLabel: 'Search',
191
195
  },
192
196
  parameters: figmaPrimaryDesign,
@@ -166,4 +166,43 @@ describe('Select', () => {
166
166
  playstation5.label,
167
167
  )
168
168
  })
169
+
170
+ describe('when isClereable is false', () => {
171
+ it('hides deselect button', async () => {
172
+ const user = userEvent.setup()
173
+
174
+ render(
175
+ <Select
176
+ label="Videogames"
177
+ name="select-videogames"
178
+ isSearchable
179
+ disabled
180
+ defaultValue={playstation5.id}
181
+ options={OPTIONS}
182
+ isClereable={false}
183
+ />,
184
+ )
185
+
186
+ expect(screen.queryByLabelText(/clear/i)).not.toBeInTheDocument()
187
+ })
188
+
189
+ it('renders first option by default if no other is passed', async () => {
190
+ const user = userEvent.setup()
191
+
192
+ render(
193
+ <Select
194
+ isClereable={false}
195
+ helpText="This text can help you"
196
+ label="Videogames"
197
+ name="videogames"
198
+ options={OPTIONS}
199
+ placeholder="Select your favourite gaming system..."
200
+ />,
201
+ )
202
+
203
+ expect(screen.getByLabelText('Videogames')).toHaveTextContent(
204
+ 'Nintendo Switch',
205
+ )
206
+ })
207
+ })
169
208
  })