UNPKG

@mui/x-date-pickers

Version:

The community edition of the MUI X Date and Time Picker components.

29 lines 1.21 kB
import * as React from 'react'; /** * Generate the props to pass to the container element of each section of the field. * @param {UseFieldSectionContainerPropsParameters} parameters The parameters of the hook. * @returns {UseFieldSectionContainerPropsReturnValue} The props to forward to the container element of each section of the field. */ export function useFieldSectionContainerProps(parameters) { const { stateResponse: { // Methods to update the states setSelectedSections }, internalPropsWithDefaults: { disabled = false } } = parameters; const createHandleClick = React.useCallback(sectionIndex => event => { // The click event on the clear button would propagate to the input, trigger this handler and result in a wrong section selection. // We avoid this by checking if the call to this function is actually intended, or a side effect. if (disabled || event.isDefaultPrevented()) { return; } setSelectedSections(sectionIndex); }, [disabled, setSelectedSections]); return React.useCallback(sectionIndex => ({ 'data-sectionindex': sectionIndex, onClick: createHandleClick(sectionIndex) }), [createHandleClick]); }