@castlabs/ui 8.0.0 → 8.1.1

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.
@@ -1,4 +1,4 @@
1
- /* @castlabs/ui v8.0.0 */
1
+ /* @castlabs/ui v8.1.1 */
2
2
 
3
3
  /*!
4
4
  * Bootstrap v5.3.8 (https://getbootstrap.com/)
@@ -918,6 +918,14 @@ function getDomain () {
918
918
  // -----------------------------------------------------------------------------
919
919
 
920
920
  let modal = null // the open modal (if any)
921
+ let modalDelay = null // a just-closed modal to circumvent unlucky event order
922
+
923
+ function setModalDelay (newModal) {
924
+ modal = newModal
925
+ setTimeout(function () {
926
+ modalDelay = newModal
927
+ }, 10)
928
+ }
921
929
 
922
930
  /**
923
931
  * Hide a bootstrap modal via it's ID.
@@ -928,7 +936,7 @@ let modal = null // the open modal (if any)
928
936
  */
929
937
  function clModalHide () {
930
938
  modal?.hide()
931
- modal = null
939
+ setModalDelay(null)
932
940
  }
933
941
 
934
942
  /**
@@ -945,10 +953,11 @@ function clModalShow (id, value) {
945
953
  // find & show the modal
946
954
  const element = document.getElementById(id)
947
955
  if (element) {
948
- modal = new bootstrap.Modal(element, { backdrop: 'static' })
949
- modal.value = value
950
- modal.id = id
951
- modal.show()
956
+ const newModal = new bootstrap.Modal(element, { backdrop: 'static' })
957
+ newModal.value = value
958
+ newModal.id = id
959
+ newModal.show()
960
+ setModalDelay(newModal)
952
961
 
953
962
  // focus the first auto-focus field in the Modal
954
963
  const autofocus = document.querySelector(`#${id} [autofocus]`)
@@ -973,8 +982,16 @@ function clModalValue (id) {
973
982
  */
974
983
  function clModalIsShown (modalId) {
975
984
  if (!modal) return false
976
- if (!modalId) return modal._isShown
977
- return modal.id === modalId && modal._isShown
985
+ if (modal._isShown) return true
986
+ return modal.id === modalId
987
+ }
988
+
989
+ /**
990
+ * Determine if a modal is/was open. It considers modal a few more ms as open, as
991
+ * sometimes browser/bootstrap events might fire in unlucky orders.
992
+ */
993
+ function clModalWasShown () {
994
+ return !!modalDelay
978
995
  }
979
996
 
980
997
  /**
@@ -1165,7 +1182,7 @@ function clFormFieldFocusFirstInvalid (formId, moreSelectors = []) {
1165
1182
  const invalid = document.querySelector(
1166
1183
  clSubselectorQuery(`#${formId}`, [':invalid', '.invalid', ...moreSelectors])
1167
1184
  )
1168
- invalid?.focus()
1185
+ invalid?.focus({ focusVisible: true })
1169
1186
  }
1170
1187
 
1171
1188
  function clSubselectorQuery (main, subselectors) {