@pocketprep/ui-kit 3.4.38 → 3.4.40

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.
@@ -49,6 +49,7 @@ export default class ModalContainer extends Vue {
49
49
  @Prop({ default: false }) showCloseButton!: boolean
50
50
  @Prop({ default: () => ({}) }) customCloseStyles?: { [key: string]: unknown }
51
51
  @Prop({ default: false }) isDarkMode!: boolean
52
+ @Prop({ default: true }) trapFocus!: boolean
52
53
 
53
54
  focusListener: Parameters<typeof addEventListener>[1] | null = null
54
55
  savedYPosition = 0
@@ -74,51 +75,53 @@ export default class ModalContainer extends Vue {
74
75
  }
75
76
 
76
77
  // Trap the user's focus within the modal - don't allow focusing elements behind the overlay
77
- this.focusListener = event => {
78
- if (this.modalNumber === this.numberOfModals()) { // Only focus on the last open panel
79
- const target = (event as FocusEvent).target as HTMLElement // The element receiving focus
80
- const isFocusOutside = target && modalContainerEl && !modalContainerEl.contains(target)
81
- const hasCalendarClass = target
82
- && Array.from(target.classList).find(
83
- c => c === 'button-next-month' || c === 'button-previous-month' || c === 'day-item'
84
- )
85
- if (isFocusOutside && !hasCalendarClass) {
86
- const focusableModalChildren = Array.from<HTMLElement>(modalContainerEl.querySelectorAll(
87
- focusableSelectors
88
- ))
89
- const firstFocusableModalChild = focusableModalChildren.find(
90
- el => !!el.getBoundingClientRect().width
91
- )
92
- const reversedModalChildren = [ ...focusableModalChildren ].reverse()
93
- const lastFocusableModalChild = reversedModalChildren.find(
94
- el => !!el.getBoundingClientRect().width
95
- )
96
- if (firstFocusableModalChild) {
97
- const relatedTarget = (event as FocusEvent).relatedTarget // The element last focused
98
- if (relatedTarget === firstFocusableModalChild && lastFocusableModalChild) {
99
- // If focus moves from first element -> outside modal, focus the last element instead
100
- lastFocusableModalChild.focus()
101
- } else if (relatedTarget === lastFocusableModalChild && firstFocusableModalChild) {
102
- // If focus moves from last element -> outside modal, focus the first element instead
103
- firstFocusableModalChild.focus()
104
- } else if (relatedTarget && relatedTarget instanceof HTMLElement) {
105
- // If focus goes outside in a different way, return focus to where it came from if possible
106
- relatedTarget.focus()
78
+ if (this.trapFocus) {
79
+ this.focusListener = event => {
80
+ if (this.modalNumber === this.numberOfModals()) { // Only focus on the last open panel
81
+ const target = (event as FocusEvent).target as HTMLElement // The element receiving focus
82
+ const isFocusOutside = target && modalContainerEl && !modalContainerEl.contains(target)
83
+ const hasCalendarClass = target
84
+ && Array.from(target.classList).find(
85
+ c => c === 'button-next-month' || c === 'button-previous-month' || c === 'day-item'
86
+ )
87
+ if (isFocusOutside && !hasCalendarClass) {
88
+ const focusableModalChildren = Array.from<HTMLElement>(modalContainerEl.querySelectorAll(
89
+ focusableSelectors
90
+ ))
91
+ const firstFocusableModalChild = focusableModalChildren.find(
92
+ el => !!el.getBoundingClientRect().width
93
+ )
94
+ const reversedModalChildren = [ ...focusableModalChildren ].reverse()
95
+ const lastFocusableModalChild = reversedModalChildren.find(
96
+ el => !!el.getBoundingClientRect().width
97
+ )
98
+ if (firstFocusableModalChild) {
99
+ const relatedTarget = (event as FocusEvent).relatedTarget // The element last focused
100
+ if (relatedTarget === firstFocusableModalChild && lastFocusableModalChild) {
101
+ // If focus moves from first element -> outside modal, focus the last element instead
102
+ lastFocusableModalChild.focus()
103
+ } else if (relatedTarget === lastFocusableModalChild && firstFocusableModalChild) {
104
+ // If focus moves from last element -> outside modal, focus the first element instead
105
+ firstFocusableModalChild.focus()
106
+ } else if (relatedTarget && relatedTarget instanceof HTMLElement) {
107
+ // If focus goes outside in a different way, return focus to where it came from if possible
108
+ relatedTarget.focus()
109
+ } else {
110
+ // Otherwise, just return focus to the first element
111
+ firstFocusableModalChild.focus()
112
+ }
107
113
  } else {
108
- // Otherwise, just return focus to the first element
109
- firstFocusableModalChild.focus()
114
+ // If the modal doesn't have any focusable children, focus the container instead
115
+ if (modalContainerEl.tabIndex === -1) {
116
+ modalContainerEl.tabIndex = 0
117
+ }
118
+ modalContainerEl.focus()
110
119
  }
111
- } else {
112
- // If the modal doesn't have any focusable children, focus the container instead
113
- if (modalContainerEl.tabIndex === -1) {
114
- modalContainerEl.tabIndex = 0
115
- }
116
- modalContainerEl.focus()
117
120
  }
118
121
  }
119
122
  }
123
+ document.addEventListener('focusin', this.focusListener)
120
124
  }
121
- document.addEventListener('focusin', this.focusListener)
122
125
 
123
126
  // prevent scrolling outside of modal
124
127
  const openModalCount = Number(document.body.getAttribute('data-openModalCount'))
@@ -48,7 +48,7 @@ export default class Tag extends Vue {
48
48
  font-size: 14px;
49
49
  height: 19px;
50
50
  line-height: 19px;
51
- padding: 0 6px;
51
+ padding: 0 4px;
52
52
  border-radius: 3px;
53
53
  text-align: center;
54
54
  margin-left: 6px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pocketprep/ui-kit",
3
- "version": "3.4.38",
3
+ "version": "3.4.40",
4
4
  "description": "Pocket Prep UI Kit",
5
5
  "author": "pocketprep",
6
6
  "scripts": {