Giter VIP home page Giter VIP logo

Comments (12)

sakhnyuk avatar sakhnyuk commented on August 31, 2024 1

Hi, @martpie

I think you can try to add your components with classNames by special props. But don't forget to forward the props object from the handler to your component.
So example below:

class CustomScrollbars extends Component {
  render() {
    return (
      <Scrollbars
        renderTrackHorizontal={props => <div {...props} className="track-horizontal"/>}
        renderTrackVertical={props => <div {...props} className="track-vertical"/>}
        renderThumbHorizontal={props => <div {...props} className="thumb-horizontal"/>}
        renderThumbVertical={props => <div {...props} className="thumb-vertical"/>}
        renderView={props => <div {...props} className="view"/>}>
        {this.props.children}
      </Scrollbars>
    );
  }
}

from rc-scrollbars.

martpie avatar martpie commented on August 31, 2024 1

Actually, I wonder if it should not forward everything ({...rest}?) from <Scrollbars>, attaching an onScroll on <Scrollbar> does not work either

from rc-scrollbars.

martpie avatar martpie commented on August 31, 2024 1

@Tomassito actually yes, I think I used a @ts-ignore here and it's still working. (It was valid in react-custom-scrollbars at least)

edit: yes I can confirm: TS does not accept it, but it works (for the outer wrapper)

from rc-scrollbars.

martpie avatar martpie commented on August 31, 2024

I think there is an issue here:

className: 'scrollView',

shouldn't it forwards props's className as well?

from rc-scrollbars.

Tomassito avatar Tomassito commented on August 31, 2024

@martpie do you want to apply the className to the Container (outer) or View (inner) element?
Because in the initial question you mention outer and now you refer to the inner...

from rc-scrollbars.

sakhnyuk avatar sakhnyuk commented on August 31, 2024

I think there is an issue here:

className: 'scrollView',

shouldn't it forwards props's className as well?

That's right. I will check how props passing from renderView. ClassNames should be merged I think

from rc-scrollbars.

martpie avatar martpie commented on August 31, 2024

Maybe I should provide more context 😄

So here's my component:

import React, { useCallback } from 'react';
import Scrollbars from 'react-custom-scrollbars';

import styles from './CustomScrollbar.module.css';

interface Props {
  className: string;
  onScroll: React.UIEventHandler<any>;
}

const CustomScrollbar: React.FC<Props> = (props) => {
  const getRenderView = useCallback((props: any) => {
    console.log(props);
    return <div {...props} className={styles.renderView} />;
  }, []);

  const getTrackVertical = useCallback((props: any) => {
    return <div {...props} className={styles.verticalTrack} />;
  }, []);

  const getThumbVertical = useCallback((props: any) => {
    return <div {...props} className={styles.verticalThumb} />;
  }, []);

  return (
    <Scrollbars
      className={props.className}
      onScroll={props.onScroll}
      renderView={getRenderView}
      renderTrackVertical={getTrackVertical}
      renderThumbVertical={getThumbVertical}
      autoHide
      autoHideTimeout={1000}
    >
      {props.children}
    </Scrollbars>
  );
};

export default CustomScrollbar;

Nothing to fancy there, this was using react-custom-scrollbars. This is what the DOM looks like:

Screen Shot 2020-12-28 at 12 44 06

tracks-list-body__xxx is my component props.className.

Now after switcing to rc_scrollbars, the DOM looks like the following:

Screen Shot 2020-12-28 at 12 46 17

So indeed, the outer wrapper looks good, and the inner seems to not accept className.

Thank you for taking the time for looking into it, I really appreciate 🙌

from rc-scrollbars.

sakhnyuk avatar sakhnyuk commented on August 31, 2024

Actually, I wonder if it should not forward everything ({...rest}?) from <Scrollbars>, attaching an onScroll on <Scrollbar> does not work either

ScrollBars has its own list of props. It is using right from component and you can check that.
Events tracking by native API (addEventListener and removeEvent...) and onScroll prop calling there.

Custom view and tracks are only about style.

from rc-scrollbars.

sakhnyuk avatar sakhnyuk commented on August 31, 2024

@martpie alright!
Thank you for your example. 👍
I can fix that today.

from rc-scrollbars.

Tomassito avatar Tomassito commented on August 31, 2024

@martpie Thanks for the example (they always work best :) ) .
Speaking of className - do you not get a TS error when you provide this prop to the Scrollbars component??

from rc-scrollbars.

sakhnyuk avatar sakhnyuk commented on August 31, 2024

@martpie
I deployed v1.0.3 with deleted className prop.

from rc-scrollbars.

martpie avatar martpie commented on August 31, 2024

I can confirm it works fine, thanks! 🙌

from rc-scrollbars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.