Skip to content

Resolved Bug 2019 : Design System > Component > Select List > Search results takes more time to show list thus before showing search results it shows message "No Records". #2026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions raaghu-elements/src/rds-select-list/rds-select-list.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,13 @@
margin-top: 3px !important;
}

.custom-select__loading-indicator {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
margin-left: -10px;
top: 50%;
transform: translateY(-50%);
z-index: 1;
}
68 changes: 55 additions & 13 deletions raaghu-elements/src/rds-select-list/rds-select-list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState, useEffect } from "react";
import Select, { components } from "react-select";
import "./rds-select-list.css";
import RdsSpinner from "../rds-spinner";
import { SpinnerSize } from "../rds-spinner/rds-spinner";

export interface RdsSelectProps {
size?: "small" | "large" | "medium" | string;
Expand Down Expand Up @@ -58,18 +60,15 @@ const RdsSelectList = (props: RdsSelectProps) => {
const [selectedValue, setSelectedValue] = useState<any | null>(
props.isMultiple ? [] : null
);
const [reset, setIsReset] = useState<boolean>(false);

const [isSearching, setIsSearching] = useState(false);
const [searchTimer, setSearchTimer] = useState<NodeJS.Timeout | null>(null);
const showLabel = props.showLabel === undefined ? true : props.showLabel;
const reset = props.reset || false;

useEffect(() => {
if (props.reset) {
setIsReset(true);
if (props.selectedValue !== undefined) {
setSelectedValue(props.selectedValue);
}
}, [props.reset]);

const showLabel = props.showLabel ?? true;

useEffect(() => {
setSelectedValue(props.selectedValue);
}, [props.selectedValue]);

// Create a fixed array of select items without the "Select All" option
Expand All @@ -87,8 +86,6 @@ const RdsSelectList = (props: RdsSelectProps) => {
: regularItems;

const handleSelectChange = (items: any) => {
setIsReset(false);

if (props.isMultiple) {
if (items && items.some((item: any) => item.value === "select_all")) {
const wasSelectAllAlreadySelected = selectedValue?.includes("select_all");
Expand Down Expand Up @@ -279,6 +276,49 @@ const RdsSelectList = (props: RdsSelectProps) => {
);
};

// Added Spinner
const customComponents = {
...props.isMultiple ? { Option } : {},
LoadingIndicator: () => (
<div className="custom-select__loading-indicator" data-testid="loading-spinner">
<RdsSpinner
spinnerType="border"
colorVariant="primary"
width="16px"
height="16px"
borderWidth="2px"
size={SpinnerSize.Small}
/>
</div>
),
IndicatorSeparator: () => null
};

const handleInputChange = (inputValue: string) => {
setIsSearching(true);
if (searchTimer) {
clearTimeout(searchTimer);
}
const timer = setTimeout(() => {
setIsSearching(false);
}, 500);
setSearchTimer(timer);
};

useEffect(() => {
return () => {
if (searchTimer) {
clearTimeout(searchTimer);
}
};
}, [searchTimer]);

useEffect(() => {
if (reset) {
setSelectedValue(props.isMultiple ? [] : null);
}
}, [reset, props.isMultiple]);

return (
<div className={`${props.classes} mt-2`}>
<div className="d-flex mb-1">
Expand All @@ -298,8 +338,9 @@ const RdsSelectList = (props: RdsSelectProps) => {
isMulti={props.isMultiple}
closeMenuOnSelect={!props.isMultiple}
hideSelectedOptions={false}
components={props.isMultiple ? { Option } : undefined}
components={customComponents}
onChange={handleSelectChange}
onInputChange={handleInputChange}
value={reset === true ? null : selectedItem}
placeholder={props.placeholder}
isSearchable={props.isSearchable}
Expand All @@ -308,6 +349,7 @@ const RdsSelectList = (props: RdsSelectProps) => {
aria-label="select example"
data-testid={props.dataTestId}
styles={customStyles}
isLoading={isSearching}
/>
{props.showHint && (
<p className="my-1 text-black-50">
Expand Down
Loading