react-mentions icon indicating copy to clipboard operation
react-mentions copied to clipboard

Loading indicator during mention data fetch

Open ruswerner opened this issue 6 years ago • 5 comments

Steps to reproduce:

  1. Create a <Mention> component with a function for the data prop, which async fetches results from a server

Expected behaviour:

The suggestions panel is immediately shown with a loading (spinner) indicator, until the data is fetched and passed to the callback argument.

Observed behaviour:

The suggestions panel does not show until after the data is fetched.

Workaround:

Please tell.

ruswerner avatar Aug 08 '18 04:08 ruswerner

We do render a LoadingIndicator element, which just renders 5 divs you can style with CSS to realize a spinner animation. This is not really documented so far, but here's an example for some spinner inline styles (of course you can achieve the same with css):

import { css } from 'glamor'
import { MentionsInput } from 'react-mentions'

const stretchdelay = css.keyframes({
  '0%': { transform: 'scaleY(0.4)' },
  '40%': { transform: 'scaleY(0.4)' },
  '100%': { transform: 'scaleY(0.4)' },

  '20%': { transform: 'scaleY(1.0)' },
})

const style = {
    loadingIndicator: {
      spinner: {
        marginTop: 4,
        marginBottom: 4,

        width: 100,
        height: 8,

        textAlign: 'center',
        fontSize: '11px',

        element: {
          display: 'inline-block',

          backgroundColor: '#999',

          height: '100%',
          width: 2,

          marginLeft: 3,
          marginRight: 3,

          animation: 'x 1.2s infinite ease-in-out',
          animationName: stretchdelay,
        },

        element2: { animationDelay: '-1.1s' },
        element3: { animationDelay: '-1.0s' },
        element4: { animationDelay: '-0.9s' },
        element5: { animationDelay: '-0.8s' },
      },
    },
}

<MentionsInput style={style} ... />

jfschwarz avatar Aug 10 '18 07:08 jfschwarz

Any idea why the LoadingIndicator is not rendered for me? Anything I need to set in the props?

I'm using the latest version 2.3.0.

Thanks in advance

UPDATE: Need to pass isLoading property to <Mention> in order for the loadingIndicator to be rendered. Hopefully this will be documented one day 😉

screen shot 2018-09-30 at 3 26 04 pm

kalemi19 avatar Sep 30 '18 13:09 kalemi19

It isn't working for me. When using customSuggestionsContainer for loading on the MentionsInput component, it only becomes active in the event that results are found (I know that customSuggestionsContainer is not for that but i tried anyways). Upon invoking the data function, the entire list becomes obscured until the results appear. Which defies logic.

CalvinJamesHeath avatar Nov 12 '23 00:11 CalvinJamesHeath