@bpmn-io/properties-panel 1.6.0 → 1.6.2

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.
package/dist/index.esm.js CHANGED
@@ -974,6 +974,9 @@ function ListGroup(props) {
974
974
  const onShow = useCallback(() => setOpen(true), [setOpen]);
975
975
  const [ordering, setOrdering] = useState([]);
976
976
  const [newItemAdded, setNewItemAdded] = useState(false);
977
+
978
+ // Flag to mark that add button was clicked in the last render cycle
979
+ const [addTriggered, setAddTriggered] = useState(false);
977
980
  const prevItems = usePrevious(items);
978
981
  const prevElement = usePrevious(element);
979
982
  const elementChanged = element !== prevElement;
@@ -995,6 +998,8 @@ function ListGroup(props) {
995
998
 
996
999
  // (1) items were added
997
1000
  useEffect(() => {
1001
+ // reset addTriggered flag
1002
+ setAddTriggered(false);
998
1003
  if (shouldHandleEffects && prevItems && items.length > prevItems.length) {
999
1004
  let add = [];
1000
1005
  items.forEach(item => {
@@ -1004,14 +1009,18 @@ function ListGroup(props) {
1004
1009
  });
1005
1010
  let newOrdering = ordering;
1006
1011
 
1007
- // open if not open and configured
1008
- if (!open && shouldOpen) {
1012
+ // open if not open, configured and triggered by add button
1013
+ //
1014
+ // TODO(marstamm): remove once we refactor layout handling for listGroups.
1015
+ // Ideally, opening should be handled as part of the `add` callback and
1016
+ // not be a concern for the ListGroup component.
1017
+ if (addTriggered && !open && shouldOpen) {
1009
1018
  toggleOpen();
1019
+ }
1010
1020
 
1011
- // if I opened and I should sort, then sort items
1012
- if (shouldSort) {
1013
- newOrdering = createOrdering(sortItems(items));
1014
- }
1021
+ // filter when not open and configured
1022
+ if (!open && shouldSort) {
1023
+ newOrdering = createOrdering(sortItems(items));
1015
1024
  }
1016
1025
 
1017
1026
  // add new items on top or bottom depending on sorting behavior
@@ -1022,11 +1031,11 @@ function ListGroup(props) {
1022
1031
  newOrdering.push(...add);
1023
1032
  }
1024
1033
  setOrdering(newOrdering);
1025
- setNewItemAdded(true);
1034
+ setNewItemAdded(addTriggered);
1026
1035
  } else {
1027
1036
  setNewItemAdded(false);
1028
1037
  }
1029
- }, [items, open, shouldHandleEffects]);
1038
+ }, [items, open, shouldHandleEffects, addTriggered]);
1030
1039
 
1031
1040
  // (2) sort items on open if shouldSort is set
1032
1041
  useEffect(() => {
@@ -1056,6 +1065,10 @@ function ListGroup(props) {
1056
1065
  ...useContext(LayoutContext),
1057
1066
  onShow
1058
1067
  };
1068
+ const handleAddClick = e => {
1069
+ setAddTriggered(true);
1070
+ add(e);
1071
+ };
1059
1072
  return jsxs("div", {
1060
1073
  class: "bio-properties-panel-group",
1061
1074
  "data-group-id": 'group-' + id,
@@ -1072,7 +1085,7 @@ function ListGroup(props) {
1072
1085
  children: [add ? jsxs("button", {
1073
1086
  title: "Create new list item",
1074
1087
  class: "bio-properties-panel-group-header-button bio-properties-panel-add-entry",
1075
- onClick: add,
1088
+ onClick: handleAddClick,
1076
1089
  children: [jsx(CreateIcon, {}), !hasItems ? jsx("span", {
1077
1090
  class: "bio-properties-panel-add-entry-label",
1078
1091
  children: "Create"
@@ -1102,8 +1115,9 @@ function ListGroup(props) {
1102
1115
  id
1103
1116
  } = item;
1104
1117
 
1105
- // if item was added, open first or last item based on ordering
1106
- const autoOpen = newItemAdded && (shouldSort ? index === 0 : index === ordering.length - 1);
1118
+ // if item was added, open it
1119
+ // Existing items will not be affected as autoOpen is only applied on first render
1120
+ const autoOpen = newItemAdded;
1107
1121
  return createElement(ListItem, {
1108
1122
  ...item,
1109
1123
  autoOpen: autoOpen,