11import {
2+ HTMLAttributes ,
23 ForwardedRef ,
34 forwardRef ,
45 memo ,
@@ -18,22 +19,38 @@ import {chart, ChartActionResult} from '../internal/chart.js';
1819
1920export interface ChartProps extends DeepPartial < ChartOptions > {
2021 children ?: ReactNode ;
22+ container ?: HTMLAttributes < HTMLDivElement > & { ref ?: ForwardedRef < HTMLDivElement > } ;
2123 onClick ?: MouseEventHandler ;
2224 onCrosshairMove ?: MouseEventHandler ;
2325}
2426
2527export const Chart = memo ( forwardRef ( function Chart ( props : ChartProps , ref : ForwardedRef < IChartApi > ) {
28+ const { container = { } , ...rest } = props ;
29+ const { ref : containerRef , ...restContainer } = container ;
30+
2631 const [ element , setElement ] = useState < HTMLElement | null > ( null ) ;
27- const handleContainerRef = useCallback ( ( ref : HTMLElement | null ) => setElement ( ref ) , [ ] ) ;
32+ const handleContainerRef = useCallback (
33+ ( ref : HTMLDivElement | null ) => {
34+ setElement ( ref ) ;
35+ if ( containerRef ) {
36+ if ( typeof containerRef === 'function' ) {
37+ containerRef ( ref ) ;
38+ } else {
39+ containerRef . current = ref ;
40+ }
41+ }
42+ } ,
43+ [ containerRef ]
44+ ) ;
2845
2946 return (
30- < div ref = { handleContainerRef } >
31- { element !== null ? < ChartComponent { ...props } ref = { ref } container = { element } /> : null }
47+ < div ref = { handleContainerRef } { ... restContainer } >
48+ { element !== null ? < ChartComponent { ...rest } ref = { ref } container = { element } /> : null }
3249 </ div >
3350 )
3451} ) ) ;
3552
36- const ChartComponent = memo ( forwardRef ( function ChartComponent ( props : ChartProps & { container : HTMLElement } , ref : ForwardedRef < IChartApi > ) {
53+ const ChartComponent = memo ( forwardRef ( function ChartComponent ( props : Omit < ChartProps , 'container' > & { container : HTMLElement } , ref : ForwardedRef < IChartApi > ) {
3754 const { children} = props ;
3855
3956 const context = useChartAction ( props , ref ) ;
@@ -45,7 +62,7 @@ const ChartComponent = memo(forwardRef(function ChartComponent(props: ChartProps
4562 ) ;
4663} ) ) ;
4764
48- function useChartAction ( props : ChartProps & { container : HTMLElement } , ref : ForwardedRef < IChartApi > ) : MutableRefObject < LazyValue < ChartActionResult > > {
65+ function useChartAction ( props : Omit < ChartProps , 'container' > & { container : HTMLElement } , ref : ForwardedRef < IChartApi > ) : MutableRefObject < LazyValue < ChartActionResult > > {
4966 const { children, container, ...rest } = props ;
5067
5168 const context = useRef ( createLazyValue (
0 commit comments