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

How to render custom TextInput or RangeDatePicker instead of common Control #158

Open
Estasie opened this issue Jan 14, 2025 · 3 comments
Open
Labels
question Further information is requested

Comments

@Estasie
Copy link

Estasie commented Jan 14, 2025

At my project I need to use RelativeRangeDatePicker with custom input render to have ability change date manually at TextInput field (or at RangeDatePicker - it is much more comfortable with it's mask for date).
I have a problem now, because I can't even enter a number into custom rendered Input.
A simple repro:
Screenshot 2025-01-14 at 16 40 49

Expected result:
I can render different node throw renderControl not loosing it's ux and RelativeRangeDatePicker modal functionality which we see on focus.
Screenshot 2025-01-14 at 16 42 35

@ValeraS
Copy link
Collaborator

ValeraS commented Jan 23, 2025

Try something like this:

const [text, setText] = React.useState('');
return (
    <RelativeRangeDatePicker
        {...props}
        renderControl={({open, title, triggerProps, ref}) => {
            return (
                <TextInput
                    ref={ref}
                    value={open ? title : text}
                    onUpdate={setText}
                    readOnly={open}
                    endContent={
                        <Button size="s" component="button" {...triggerProps} extraProps={{...triggerProps}}>
                            <Icon data={Calendar} />
                        </Button>
                    }
                />
            );
        }}
    />
);

@ValeraS ValeraS added the question Further information is requested label Jan 23, 2025
@Estasie
Copy link
Author

Estasie commented Jan 27, 2025

I still can't change the input value, when it's "focused" (the picker modal appears)
First of all, I need to render formatted text, when picker open.
value={open ? text : title}

And need to render picker when I click into TextInput. As I had mentioned at the issue below (second picture) Can edit the input and use modal functionality. Modal should appear not only when I click calendar button, but when I focus the input
@ValeraS

@ValeraS
Copy link
Collaborator

ValeraS commented Jan 27, 2025

then try to use dialog itself :

function DatePicker(props) {
        const state = useRelativeRangeDatePickerState(props);
        const [open, setOpen] = React.useState(false);
        const [text, setText] = React.useState('');
        const ref = React.useRef<HTMLElement>(null);

        return (
            <React.Fragment>
                <TextInput
                    ref={ref}
                    value={text}
                    onUpdate={setText}
                    onFocus={() => {
                        setOpen(true);
                    }}
                />
                <RelativeRangeDatePickerDialog
                    anchorRef={ref}
                    props={props}
                    state={state}
                    open={open}
                    onClose={() => {
                        setOpen(false);
                    }}
                    // added in 2.12.0
                    disableFocusTrap
                />
            </React.Fragment>
        );
},

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

No branches or pull requests

2 participants