@contentful/field-editor-rich-text 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -577,6 +577,10 @@ var useCommandList = function useCommandList(commandItems, container) {
577
577
  selectedItem = _React$useState[0],
578
578
  setSelectedItem = _React$useState[1];
579
579
 
580
+ var _React$useState2 = useState(commandItems.length > 0),
581
+ isOpen = _React$useState2[0],
582
+ setIsOpen = _React$useState2[1];
583
+
580
584
  useEffect(function () {
581
585
  if (!(container != null && container.current)) {
582
586
  return;
@@ -641,8 +645,21 @@ var useCommandList = function useCommandList(commandItems, container) {
641
645
  return window.removeEventListener('keydown', handleKeyDown);
642
646
  };
643
647
  }, [commandItems, container, selectedItem]);
648
+ useEffect(function () {
649
+ var handleClick = function handleClick(event) {
650
+ if (container.current && !container.current.contains(event.target)) {
651
+ setIsOpen(false);
652
+ }
653
+ };
654
+
655
+ document.addEventListener('click', handleClick);
656
+ return function () {
657
+ document.removeEventListener('click', handleClick);
658
+ };
659
+ }, [container]);
644
660
  return {
645
- selectedItem: selectedItem
661
+ selectedItem: selectedItem,
662
+ isOpen: isOpen
646
663
  };
647
664
  };
648
665
 
@@ -1851,11 +1868,8 @@ var CommandList = function CommandList(_ref5) {
1851
1868
  var commandItems = useCommands(sdk, query, editor);
1852
1869
 
1853
1870
  var _useCommandList = useCommandList(commandItems, container),
1854
- selectedItem = _useCommandList.selectedItem;
1855
-
1856
- if (commandItems.length === 0) {
1857
- return null;
1858
- }
1871
+ selectedItem = _useCommandList.selectedItem,
1872
+ isOpen = _useCommandList.isOpen;
1859
1873
 
1860
1874
  return /*#__PURE__*/createElement("div", {
1861
1875
  className: styles.container,
@@ -1867,7 +1881,7 @@ var CommandList = function CommandList(_ref5) {
1867
1881
  }, /*#__PURE__*/createElement(ScreenReaderOnly, null, "Richtext commands. Currently focused item: ", selectedItem, ". Press ", /*#__PURE__*/createElement("kbd", null, "enter"), " to select, ", /*#__PURE__*/createElement("kbd", null, "arrows"), " to navigate, ", /*#__PURE__*/createElement("kbd", null, "escape"), " to close.")), /*#__PURE__*/createElement("div", {
1868
1882
  "aria-hidden": true
1869
1883
  }, /*#__PURE__*/createElement(Popover, {
1870
- isOpen: true,
1884
+ isOpen: isOpen,
1871
1885
  usePortal: false,
1872
1886
 
1873
1887
  /* eslint-disable-next-line jsx-a11y/no-autofocus -- we want to keep focus on text input*/