1.0.23 • Published 2 months ago

react-virtualized-auto-sizer v1.0.23

Weekly downloads
361,990
License
MIT
Repository
github
Last release
2 months ago

react-virtualized-auto-sizer

Standalone version of the AutoSizer component from react-virtualized.

If you like this project, 🎉 become a sponsor or ☕ buy me a coffee

Install

npm install --save react-virtualized-auto-sizer

Documentation

PropertyTypeRequired?Description
childrenFunctionFunction responsible for rendering children. This function should implement the following signature: ({ height?: number \| undefined, width?: number \| undefined }) => PropTypes.element
classNameStringOptional custom CSS class name to attach to root AutoSizer element. This is an advanced property and is not typically necessary.
defaultHeightNumberHeight passed to child for initial render; useful for server-side rendering. This value will be overridden with an accurate height after mounting.
defaultWidthNumberWidth passed to child for initial render; useful for server-side rendering. This value will be overridden with an accurate width after mounting.
disableHeightBooleanFixed height; if specified, the child's height property will not be managed
disableWidthBooleanFixed width; if specified, the child's width property will not be managed
nonceStringNonce of the inlined stylesheets for Content Security Policy
onResizeFunctionCallback to be invoked on-resize; it is passed the following named parameters: ({ height: number, width: number }).
styleObjectOptional custom inline style to attach to root AutoSizer element. This is an advanced property and is not typically necessary.
tagNamestringOptional HTML tag name for root element; defaults to "div"

Examples

Some components (like those found in react-window or react-virtualized) require numeric width and height parameters. The AutoSizer component can be useful if you want to pass percentage based dimensions.

import AutoSizer from "react-virtualized-auto-sizer";

// UI
<AutoSizer>
  {({ height, width }) => {
    // Use these actual sizes to calculate your percentage based sizes
  }}
</AutoSizer>;

FAQs

Can I use this component with flexbox?

Flex containers don't prevent their children from growing and AutoSizer greedily grows to fill as much space as possible. Combining the two can be problematic. The simple way to fix this is to nest AutoSizer inside of a block element (like a <div>) rather than putting it as a direct child of the flex container, like so:

<div style={{ display: 'flex' }}>
  <!-- Other children... -->
  <div style={{ flex: '1 1 auto' }}>
    <AutoSizer>
      {({ height, width }) => (
        <Component
          width={width}
          height={height}
          {...props}
        />
      )}
    </AutoSizer>
  </div>
</div>

Why is AutoSizer passing a height of 0?

AutoSizer expands to fill its parent but it will not stretch the parent. This is done to prevent problems with flexbox layouts. If AutoSizer is reporting a height (or width) of 0- then it's likely that the parent element (or one of its parents) has a height of 0.

The solution to this problem is often to add height: 100% or flex: 1 to the parent. One easy way to test this is to add a style property (eg background-color: red;) to the parent to visually confirm that it is the expected size.

Can I use AutoSizer to manage only width or height (not both)?

You can use AutoSizer to control only one dimension of its child component using the disableHeight or disableWidth attributes. For example, a fixed-height component that should grow to fill the available width can be created like so:

<AutoSizer disableHeight>
  {({width}) => <Component height={200} width={width} {...props} />}
</AutoSizer>

Module parsing fails because of an unexpected token?

This package targets ECMAScript 2015 (ES6) and requires a build tool such as babel-loader that is capable of parsing the ES6 class syntax.

Can this component work with a Content Security Policy?

The specification of Content Security Policy describes as the following:

This document defines Content Security Policy, a mechanism web applications can use to mitigate a broad class of content injection vulnerabilities, such as cross-site scripting (XSS).

To apply Content Security Policy, pass a nonce to AutoSizer and add a matching nonce-source to the Content-Security-Policy field in HTTP header.

@invisionag/componentsbaseui@elliemae/ds-shared@elliemae/ds-shuttle@bondsports/utils@pangolindex/components@corva/ui@arthswap/widgets@openos.com/uniswapinternal-dash-explore@neggi/baseuireact-virt-tablenavio-uidecoupled-front-end@edunad/react-hex-editor@open-raven/react-styleguidekhodroinja-ui-coremirador-biblissimamattermost-webapp-libxr3-spokexrchat-spokereact-tv-cmp-testmoneko.consolepucomponents8pucomponents16notes-fwreact-highlightable-datasheetarclight-react@joey.andres/eui@instabase.com/pollenchinese-mirador@gelatonetwork/stop-limit-orders-reactpangea-widgetschonky-trrsytchonky-trrystcoffeephin-uiprogram_leader_portal_pyscrm-admininst_site_1inst_site_npm@infinitebrahmanuniverse/nolb-react-v@compassdigital/compassdigital.components.distilr@pixiebrix/extensionreact-devtools-sharedmonday-ui-react-core@ambassify/ui-utility-autosizera-miradorflare-dispatchxt-common-comp@edhos/uixcim-codesandboxwazuh-wuiwaterfall-sdkwell-seismic-common-componentsweb-toolkitwebapp-joostlywlacwido-widgetwido-widget-v4wido-widget-v5tile-map-sstest-monday-ui-react-coretest-swap-widgetststststuhnoxi-music-webuhnoxi-music-web-build@europeana/mirador@exivity/ui@everything-registry/sub-chunk-2622@euax-ui/data-display@friggeco/uniswap-widgets@etherealengine/editor@engyalo/glide-data-grid@fabriziospadaro/chonky@fusion-ui/baseweb@fractal-software/fractal-messaging@envanik/components@epallinone/chonky@gaut/ui@gelatonetwork/gelato-front-end-lib@gelatonetwork/limit-orders-react@gelatonetwork/range-orders-reactval-react-uiubeswap-headerubeswap-swap-devvoxeet-react-components-edotuniswap-widgets-for-extensionuniswap-widgets-qwq@inoft/eui@inv3rse/design-systemfilemanager-library-ver-eccfileread-library-legacyfc-chonky@irrelon/react-financial-charts-utils@intimefinance/widgets@honeycomb-finance/token-drawer@honeycomb-finance/walletmodal@honeycomb-finance/pools@honeycomb-finance/bridge@iofjuupasli/react-google-flight-datepicker
1.0.23

2 months ago

1.0.22

3 months ago

1.0.21

3 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.20

11 months ago

1.0.17

12 months ago

1.0.16

12 months ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.7

2 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago