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.

Picker does not close

See original GitHub issue

I am not able to close the pickers I open by clicking outside the picker element.

This is because I have put the picker in a component which has transform applied to an ancestor. Therefore, the cover element in Picker, which has a position: fixed actually starts behaving like a position: absolute element (transforms change the container element of fixed-pos elements)

screenshot 43

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
arecvlohecommented, Oct 20, 2017

I think the easiest way to handle this is to put a wrapper around the color picker, which you already do so that it displays above content around it. Then just apply a onMouseLeave event to close it. I think this is better than having to create refs for each color picker. This will create the onBlur effect which I think is ideal.

components.js

export const ColorPickerWrapper = styled.div`
  position: absolute;
  z-index: 2;
`;

export const ColorPicker = ({ onMouseLeave, onChange, color }) => (
  <ColorPickerWrapper onMouseLeave={onMouseLeave}>
    <BlockPicker color={color} colors={defaultColors} onChangeComplete={onChange} triangle="hide" />
  </ColorPickerWrapper>
);

component.js

{showBorderPicker && (
  <ColorPicker
     color={styles.borderColor}
     onChange={handleChangeStyles(['event', 'styles', 'borderColor'])}
     onMouseLeave={handleShowPicker('showBorderPicker')}
 />
)}
0reactions
Dror-Barcommented, Mar 3, 2020

@liziver Nice trick, thanks for sharing. I had a solution of my own using onMouseEnter and onMouseLeave, but your seems better / simpler.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date picker window is not close - Stack Overflow
As you mentioned this is an issue with IE. However, you can add a custom function to check when one leaves or clicks...
Read more >
picker is not closing on modal · Issue #117 - GitHub
Hey! I had resolved this issue with hook. Add ref to your DatePicker component and use closeCalendar() method. Example: useOnClickOutside( ...
Read more >
[DateTimePicker] Picker does not close when popup is hidden
Click outside of the picker to close it 4. Open the picker again by clicking on the input box Expected: The picker should...
Read more >
Time picker and date picker are not closing after selecting the ...
1) Everything is working fine. But it doesnot close on selecting the values. I need to do it twice then it will close...
Read more >
Close date picker after selecting the date - MDBootstrap
Hello, Is it possible to close date picker automatically once the date is selected there, so I don't need to click close button...
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