Skip to content

Commit

Permalink
dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasha Kondrashov committed Mar 3, 2024
1 parent 141008a commit 56418a2
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 87 deletions.
1 change: 0 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ export {
export {
default as Dropdown,
DropdownProps,
DropdownOnSearchChangeData,
StrictDropdownProps,
} from './dist/commonjs/modules/Dropdown'
export {
Expand Down
53 changes: 28 additions & 25 deletions src/modules/Dropdown/Dropdown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,49 +126,57 @@ export interface StrictDropdownProps {
* Called when a user adds a new item. Use this to update the options list.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props and the new item's value.
* @param {object} props - All props.
*/
onAddItem?: (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => void
onAddItem?: (
event: React.SyntheticEvent<HTMLElement>,
props: DropdownProps,
value: boolean | number | string | (boolean | number | string)[],
) => void

/**
* Called on blur.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props.
* @param {object} props - All props.
*/
onBlur?: (event: React.FocusEvent<HTMLElement>, data: DropdownProps) => void
onBlur?: (event: React.FocusEvent<HTMLElement>, props: DropdownProps) => void

/**
* Called when the user attempts to change the value.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props and proposed value.
* @param {object} props - All props.
*/
onChange?: (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => void
onChange?: (
event: React.SyntheticEvent<HTMLElement>,
props: DropdownProps,
value: boolean | number | string | (boolean | number | string)[],
) => void

/**
* Called on click.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props.
* @param {object} props - All props.
*/
onClick?: (event: React.MouseEvent<HTMLElement>, data: DropdownProps) => void
onClick?: (event: React.MouseEvent<HTMLElement>, props: DropdownProps) => void

/**
* Called when a close event happens.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props.
* @param {object} props - All props.
*/
onClose?: (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => void
onClose?: (event: React.SyntheticEvent<HTMLElement>, props: DropdownProps) => void

/**
* Called on focus.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props.
* @param {object} props - All props.
*/
onFocus?: (event: React.FocusEvent<HTMLElement>, data: DropdownProps) => void
onFocus?: (event: React.FocusEvent<HTMLElement>, props: DropdownProps) => void

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

/**
* Called when an open event happens.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props.
* @param {object} props - All props.
*/
onOpen?: (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => void
onOpen?: (event: React.SyntheticEvent<HTMLElement>, props: DropdownProps) => void

/**
* Called on search input change.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props, includes current value of searchQuery.
* @param {object} props - All props.
* @param {string} searchQuery - Current value of searchQuery.
*/
onSearchChange?: (
event: React.SyntheticEvent<HTMLElement>,
data: DropdownOnSearchChangeData,
data: DropdownProps,
searchQuery: string,
) => void

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

/* TODO: replace with DropdownProps when #1829 will be fixed:
* https://github.com/Semantic-Org/Semantic-UI-React/issues/1829
*/
export interface DropdownOnSearchChangeData extends DropdownProps {
searchQuery: string
}

declare const Dropdown: ForwardRefComponent<DropdownProps, HTMLDivElement> & {
Divider: typeof DropdownDivider
Header: typeof DropdownHeader
Expand Down
8 changes: 4 additions & 4 deletions src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class DropdownInner extends Component {
// can't rely on props.value if we are controlled
handleChange = (e, value) => {
debug('handleChange()', value)
_.invoke(this.props, 'onChange', e, { ...this.props, value })
_.invoke(this.props, 'onChange', e, this.props, value)
}

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

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

Expand Down Expand Up @@ -592,7 +592,7 @@ class DropdownInner extends Component {
const { open } = this.state
const newQuery = value

_.invoke(this.props, 'onSearchChange', e, { ...this.props, searchQuery: newQuery })
_.invoke(this.props, 'onSearchChange', e, this.props, newQuery)
this.setState({ searchQuery: newQuery, selectedIndex: 0 })

// open search dropdown on search query
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Dropdown/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default, DropdownProps, StrictDropdownProps, DropdownOnSearchChangeData } from './Dropdown'
export { default, DropdownProps, StrictDropdownProps } from './Dropdown'
Loading

0 comments on commit 56418a2

Please sign in to comment.