Skip to content

Commit b476aa0

Browse files
author
Sasha Kondrashov
committed
dropdown
1 parent 141008a commit b476aa0

File tree

3 files changed

+98
-85
lines changed

3 files changed

+98
-85
lines changed

Diff for: src/modules/Dropdown/Dropdown.d.ts

+28-25
Original file line numberDiff line numberDiff line change
@@ -126,49 +126,57 @@ export interface StrictDropdownProps {
126126
* Called when a user adds a new item. Use this to update the options list.
127127
*
128128
* @param {SyntheticEvent} event - React's original SyntheticEvent.
129-
* @param {object} data - All props and the new item's value.
129+
* @param {object} props - All props.
130130
*/
131-
onAddItem?: (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => void
131+
onAddItem?: (
132+
event: React.SyntheticEvent<HTMLElement>,
133+
props: DropdownProps,
134+
value: boolean | number | string | (boolean | number | string)[],
135+
) => void
132136

133137
/**
134138
* Called on blur.
135139
*
136140
* @param {SyntheticEvent} event - React's original SyntheticEvent.
137-
* @param {object} data - All props.
141+
* @param {object} props - All props.
138142
*/
139-
onBlur?: (event: React.FocusEvent<HTMLElement>, data: DropdownProps) => void
143+
onBlur?: (event: React.FocusEvent<HTMLElement>, props: DropdownProps) => void
140144

141145
/**
142146
* Called when the user attempts to change the value.
143147
*
144148
* @param {SyntheticEvent} event - React's original SyntheticEvent.
145-
* @param {object} data - All props and proposed value.
149+
* @param {object} props - All props.
146150
*/
147-
onChange?: (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => void
151+
onChange?: (
152+
event: React.SyntheticEvent<HTMLElement>,
153+
props: DropdownProps,
154+
value: boolean | number | string | (boolean | number | string)[],
155+
) => void
148156

149157
/**
150158
* Called on click.
151159
*
152160
* @param {SyntheticEvent} event - React's original SyntheticEvent.
153-
* @param {object} data - All props.
161+
* @param {object} props - All props.
154162
*/
155-
onClick?: (event: React.MouseEvent<HTMLElement>, data: DropdownProps) => void
163+
onClick?: (event: React.MouseEvent<HTMLElement>, props: DropdownProps) => void
156164

157165
/**
158166
* Called when a close event happens.
159167
*
160168
* @param {SyntheticEvent} event - React's original SyntheticEvent.
161-
* @param {object} data - All props.
169+
* @param {object} props - All props.
162170
*/
163-
onClose?: (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => void
171+
onClose?: (event: React.SyntheticEvent<HTMLElement>, props: DropdownProps) => void
164172

165173
/**
166174
* Called on focus.
167175
*
168176
* @param {SyntheticEvent} event - React's original SyntheticEvent.
169-
* @param {object} data - All props.
177+
* @param {object} props - All props.
170178
*/
171-
onFocus?: (event: React.FocusEvent<HTMLElement>, data: DropdownProps) => void
179+
onFocus?: (event: React.FocusEvent<HTMLElement>, props: DropdownProps) => void
172180

173181
/**
174182
* Called when a multi-select label is clicked.
@@ -182,27 +190,29 @@ export interface StrictDropdownProps {
182190
* Called on mousedown.
183191
*
184192
* @param {SyntheticEvent} event - React's original SyntheticEvent.
185-
* @param {object} data - All props.
193+
* @param {object} props - All props.
186194
*/
187-
onMouseDown?: (event: React.MouseEvent<HTMLElement>, data: DropdownProps) => void
195+
onMouseDown?: (event: React.MouseEvent<HTMLElement>, props: DropdownProps) => void
188196

189197
/**
190198
* Called when an open event happens.
191199
*
192200
* @param {SyntheticEvent} event - React's original SyntheticEvent.
193-
* @param {object} data - All props.
201+
* @param {object} props - All props.
194202
*/
195-
onOpen?: (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => void
203+
onOpen?: (event: React.SyntheticEvent<HTMLElement>, props: DropdownProps) => void
196204

197205
/**
198206
* Called on search input change.
199207
*
200208
* @param {SyntheticEvent} event - React's original SyntheticEvent.
201-
* @param {object} data - All props, includes current value of searchQuery.
209+
* @param {object} props - All props.
210+
* @param {string} searchQuery - Current value of searchQuery.
202211
*/
203212
onSearchChange?: (
204213
event: React.SyntheticEvent<HTMLElement>,
205-
data: DropdownOnSearchChangeData,
214+
data: DropdownProps,
215+
searchQuery: string,
206216
) => void
207217

208218
/** Controls whether or not the dropdown menu is displayed. */
@@ -292,13 +302,6 @@ export interface StrictDropdownProps {
292302
wrapSelection?: boolean
293303
}
294304

295-
/* TODO: replace with DropdownProps when #1829 will be fixed:
296-
* https://github.com/Semantic-Org/Semantic-UI-React/issues/1829
297-
*/
298-
export interface DropdownOnSearchChangeData extends DropdownProps {
299-
searchQuery: string
300-
}
301-
302305
declare const Dropdown: ForwardRefComponent<DropdownProps, HTMLDivElement> & {
303306
Divider: typeof DropdownDivider
304307
Header: typeof DropdownHeader

Diff for: src/modules/Dropdown/Dropdown.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class DropdownInner extends Component {
231231
// can't rely on props.value if we are controlled
232232
handleChange = (e, value) => {
233233
debug('handleChange()', value)
234-
_.invoke(this.props, 'onChange', e, { ...this.props, value })
234+
_.invoke(this.props, 'onChange', e, this.props, value)
235235
}
236236

237237
closeOnChange = (e) => {
@@ -342,7 +342,7 @@ class DropdownInner extends Component {
342342
// Heads up! This event handler should be called after `onChange`
343343
// Notify the onAddItem prop if this is a new value
344344
if (item['data-additional']) {
345-
_.invoke(this.props, 'onAddItem', e, { ...this.props, value: selectedValue })
345+
_.invoke(this.props, 'onAddItem', e, this.props, selectedValue)
346346
}
347347
}
348348

@@ -544,7 +544,7 @@ class DropdownInner extends Component {
544544
// Heads up! This event handler should be called after `onChange`
545545
// Notify the onAddItem prop if this is a new value
546546
if (isAdditionItem) {
547-
_.invoke(this.props, 'onAddItem', e, { ...this.props, value })
547+
_.invoke(this.props, 'onAddItem', e, this.props, value)
548548
}
549549
}
550550

@@ -592,7 +592,7 @@ class DropdownInner extends Component {
592592
const { open } = this.state
593593
const newQuery = value
594594

595-
_.invoke(this.props, 'onSearchChange', e, { ...this.props, searchQuery: newQuery })
595+
_.invoke(this.props, 'onSearchChange', e, this.props, newQuery)
596596
this.setState({ searchQuery: newQuery, selectedIndex: 0 })
597597

598598
// open search dropdown on search query

0 commit comments

Comments
 (0)