Skip to content
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

customize country list item height (virtuallist) #192

Open
EricSong8612 opened this issue Nov 21, 2018 · 1 comment
Open

customize country list item height (virtuallist) #192

EricSong8612 opened this issue Nov 21, 2018 · 1 comment

Comments

@EricSong8612
Copy link

Hi there, I'm trying to style the country list item with customized height. but the problem is that there is a gap between each items, which is caused by the position top value of each item i think. According to the source code, a virtual list is used here. but the parameters are hard-coded. so is there any way to change this?
screen shot 2018-11-21 at 10 06 33 am

@viktornar
Copy link

viktornar commented Jan 2, 2019

It would be great if it would be possible to pass width to virtual list as well instead of having hard coded it.

@EricSong8612 Right now I'm using a hack at some point:

export default class OverriddenReactTelephoneInput extends ReactTelephoneInput {
  getCountryDropDownList = () => {
    const data = this.state.preferredCountries.concat(this.props.onlyCountries);

    return (
      <VirtualList
        width={ 250 }
        height={ 90 }
        itemCount={ data.length }
        itemSize={ 40 }
        style={ this.props.listStyle }
        className="country-list"
        scrollToIndex={ this.state.highlightCountryIndex }
        scrollToAlignment="center"
        renderItem={ ({ index, style }) => {
          const country = data[index];
          const itemClasses = classNames(this.props.listItemClassName, {
            preferred: findIndex(this.state.preferredCountries, (c) => c.iso2 === country.iso2) >= 0,
            highlight: this.state.highlightCountryIndex === index
          });

          const inputFlagClasses = `flag ${country.iso2}`;

          return (
            <div
              key={ `flag_no_${index}` }
              data-flag-key={ `flag_no_${index}` }
              className={ itemClasses }
              data-dial-code={ country.dialCode }
              data-country-code={ country.iso2 }
              onClick={ this.handleFlagItemClick.bind(this, country) }
              style={ style }
              title={ `${country.name} - ${country.dialCode}` }
            >
              <div
                className={ inputFlagClasses }
                style={ this.getFlagStyle() }
              />
              <span className="country-name">
                { country.name }
              </span>
              <span className="dial-code">
                { `+${country.dialCode}` }
              </span>
            </div>
          );
        } }
      />
    );
  }
}

and then

 <OverriddenReactTelephoneInput
       onlyCountries={ onlyCountries }
       preferredCountries={ ['en'] }
       onChange={ this.handleCountryChange }
       initialValue={ initialValues.countryCode }
 />

I have used findIndex from lodash function since we already using it in our project.

It's also possible to override width and height with max-width and max-height in css, but then VirtualList doesn't work correctly with keyboard navigation :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants