Skip to content

Commit

Permalink
Ux/fix spinner searchable select (#1204)
Browse files Browse the repository at this point in the history
* [components] Add no result state to story

* [components] Removing spinner and fix flickering
  • Loading branch information
Kristoffer J. Sivertsen committed Feb 18, 2019
1 parent d5099ac commit 356b60f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export default class SearchableSelect extends React.PureComponent {
isOpen: false,
highlightIndex: -1,
isInputSelected: false,
arrowNavigationPosition: 0,
hasFocus: false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,14 @@ export default class StatelessSearchableSelect extends React.PureComponent {
readOnly={readOnly}
/>
<div className={styles.functions}>
{openItemElement &&
value && <span className={styles.openItem}>{openItemElement(value)}</span>}
{!readOnly &&
onClear &&
value && (
<button type="button" className={styles.clearButton} onClick={onClear}>
<CloseIcon color="inherit" />
</button>
)}
{openItemElement && value && (
<span className={styles.openItem}>{openItemElement(value)}</span>
)}
{!readOnly && onClear && value && (
<button type="button" className={styles.clearButton} onClick={onClear}>
<CloseIcon color="inherit" />
</button>
)}
{!readOnly && (
<div className={styles.arrowAndSpinnerContainer}>
{!isLoading && (
Expand Down Expand Up @@ -238,18 +237,23 @@ export default class StatelessSearchableSelect extends React.PureComponent {
<CaptureOutsideClicks
onClickOutside={isActive && isOpen ? this.handleClose : undefined}
>
<div className={styles.listContainer}>
<div
className={
items.length === 0 ? styles.listContainerNoResult : styles.listContainer
}
>
<Escapable
onEscape={event => (isActive || event.shiftKey) && this.handleClose()}
/>
{items.length === 0 &&
!isLoading && <p className={styles.noResultText}>No results</p>}
{items.length === 0 &&
isLoading && (
<div className={styles.listSpinner}>
<Spinner message="Loading items…" />
</div>
)}
<div
className={
items.length === 0 && !isLoading
? styles.noResultText
: styles.noResultTextHidden
}
>
No results
</div>
{items.length > 0 && (
<SelectMenu
items={items}
Expand Down
9 changes: 6 additions & 3 deletions packages/@sanity/components/src/selects/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ storiesOf('Selects')
max: items.length,
step: 1
})
const selectedItem = items[selected]

const hasItems = boolean('hasItems', false, 'test') || undefined

const selectedItem = (items && items[selected]) || undefined
return (
<div style={{minWidth: '320px', ...centerStyle}}>
<Sanity part="part:@sanity/components/selects/searchable" propTables={[SearchableSelect]}>
Expand All @@ -160,10 +163,10 @@ storiesOf('Selects')
onFocus={action('onFocus')}
onBlur={action('onBlur')}
onOpen={action('onOpen')}
value={selectedItem}
value={hasItems && selectedItem}
inputValue={text('Inputvalue', selectedItem && selectedItem.title, 'props')}
renderItem={renderItem}
items={items}
items={hasItems && items}
isLoading={boolean('isLoading', false, 'props')}
disabled={boolean('disabled (prop)', false, 'props')}
onClear={hasOnclear ? action('onClear') : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@
.listContainer {
composes: shadow-24dp from "part:@sanity/base/theme/shadows-style";
display: block;
min-height: 3.5rem;
max-height: 20rem;
overflow: auto;
border: 1px solid var(--component-border-color);
box-sizing: border-box;
background-color: var(--component-bg);
transition: max-height 100ms linear;
}

.listContainerNoResult {
composes: listContainer;
max-height: 4rem;
}

.listContainerHidden {
Expand All @@ -75,9 +82,18 @@
}

.noResultText {
text-align: center;
padding: 0.5em;
opacity: 0.5;
position: absolute;
width: 100%;
opacity: 1;
padding: var(--medium-padding);
transition: opacity 100ms ease-out;
transition-delay: 100ms;
}

.noResultTextHidden {
composes: noResultText;
transition: none;
opacity: 0;
}

.spinner {
Expand Down Expand Up @@ -135,10 +151,6 @@
}
}

.listSpinner {
opacity: 0.5;
}

.clearButton {
composes: textInput from 'part:@sanity/base/theme/forms/clear-button-style';
}

0 comments on commit 356b60f

Please sign in to comment.