question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Programmatically open/close date picker?

See original GitHub issue

Hi,

Is there a way to programmatically open/close the date picker from react-native-datetimepicker?

My use case is creating a component based on TouchableOpacity that opens the DatePicker when pressed (with a much bigger surface area than the tiny date picker).

RNDateTimePicker does not seem to accept a ref, nor to have an API to hide/show.

Thank you very much.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:14
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

27reactions
LouisRainecommented, Jul 5, 2021

{show && <RNDateTimePicker />}

6reactions
omarqecommented, Aug 31, 2021

I needed this too. But my current workaround is to wrap <DateTimePicker/> inside an invisible <View/>. The touch experience is not quite good, but it works though.

Example:

import React from "react"
import DateTimePicker from "@react-native-community/datetimepicker";
import { View, Text } from "react-native"

export default function CustomDateInput({ value, ...restProps }) {
    return (
        <View style={{ position: "relative" }}>
            <Text>{value}</Text>
            <View style={{ opacity: 0, position: "absolute" }}>
                <DateTimePicker value={value} {...restProps} />
            </View>
        </View>
    );
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Programmatically open/close react-native-datetimepicker?
My use case is creating a component based on TouchableOpacity that opens the DatePicker when pressed (with a much bigger surface area than ......
Read more >
New on the web: programmatically open a native date picker
The new `showPicker()` DOM methods enables developers to open a native date picker if the input element supports it.
Read more >
[OutSystems UI] DatePicker in 2.8.3 - Refresh Input Value
I cannot understand how to refresh the date in the date picker input when you want to adjust its value programmatically. Example attached...
Read more >
Programmatically open/close react-native-datetimepicker?
Coding example for the question Programmatically open/close ... return ( <View> <View> <Button onPress={showDatepicker} title="Show date picker!
Read more >
Setting a Default Date | The Visual Developers Podcast
Integrating Flatpickr.js (a flexible, third-party datepicker) into your Webflow Project ... Using Javascript to Open/Close/Clear the Calendar ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found