Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joakbjerk committed Sep 16, 2024
1 parent 9496d61 commit cc1f916
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export interface AutocompleteProps {
* Define a custom class for the internal drawer-list. This makes it possible more easily customize the drawer-list style with styled-components and the `css` style method. Defaults to `null`.
*/
drawer_class?: string;
keepSelectIndexOnDataChange?: boolean;
on_type?: (...args: any[]) => any;
on_focus?: (...args: any[]) => any;
on_blur?: (...args: any[]) => any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export default class Autocomplete extends React.PureComponent {
PropTypes.object,
PropTypes.array,
]),

keepSelectIndexOnDataChange: PropTypes.bool,
on_show: PropTypes.func,
on_type: PropTypes.func,
on_focus: PropTypes.func,
Expand Down Expand Up @@ -329,6 +329,7 @@ export default class Autocomplete extends React.PureComponent {

className: null,
children: null,
keepSelectIndexOnDataChange: false,

on_show: null,
on_hide: null,
Expand Down Expand Up @@ -1802,6 +1803,7 @@ class AutocompleteInstance extends React.PureComponent {
show_all, // eslint-disable-line
aria_live_options, // eslint-disable-line
disable_highlighting, // eslint-disable-line
keepSelectIndexOnDataChange,

...attributes
} = props
Expand Down Expand Up @@ -2084,6 +2086,7 @@ class AutocompleteInstance extends React.PureComponent {
on_key_down={this.reserveActivityHandler}
onMouseDown={this.reserveActivityHandler}
independent_width={independent_width}
keepSelectIndexOnDataChange={keepSelectIndexOnDataChange}
/>
</span>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ function PhoneNumber(props: Props) {
autoComplete="tel-country-code"
no_animation={props.noAnimation}
stretch={width === 'stretch'}
keepSelectIndexOnDataChange
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ function SelectCountry(props: Props) {
}
autoComplete="country-name"
no_animation={props.noAnimation}
keepSelectIndexOnDataChange
{...htmlAttributes}
/>
</FieldBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export interface DrawerListProps {
on_resize?: (...args: any[]) => any;
on_select?: (...args: any[]) => any;
on_state_update?: (...args: any[]) => any;
keepSelectIndexOnDataChange?: boolean;
}
export type DrawerListOptionsProps = {
children: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,15 @@ export const prepareDerivedState = (props, state) => {

// Reset selected_item and active_item on data prop change
if (!props?.keepSelectIndexOnDataChange) {
state.selected_item = null
state.active_item = null
// Sets the selected_item to be the default_value if provided
// And -1 or null if not provided, making the active item be unselected on props.data change
const defaultItem =
props.default_value !== undefined || props.default_value !== null
? getCurrentIndex(props.default_value, state.data)
: null

state.selected_item = defaultItem
state.active_item = defaultItem
}
}

Expand Down

0 comments on commit cc1f916

Please sign in to comment.