@coreui/react 4.11.0 → 4.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreui/react",
3
- "version": "4.11.0",
3
+ "version": "4.11.1",
4
4
  "description": "UI Components Library for React.js",
5
5
  "keywords": [
6
6
  "react",
@@ -200,10 +200,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
200
200
  }, [_visible])
201
201
 
202
202
  const handleClickOutside = (event: Event) => {
203
- if (
204
- modalContentRef.current &&
205
- !modalContentRef.current.contains(event.target as HTMLElement)
206
- ) {
203
+ if (modalRef.current && modalRef.current == event.target) {
207
204
  handleDismiss()
208
205
  }
209
206
  }
@@ -1,5 +1,4 @@
1
1
  import React, { forwardRef, HTMLAttributes, ReactNode, useRef, useEffect, useState } from 'react'
2
- // import { createPortal } from 'react-dom'
3
2
  import classNames from 'classnames'
4
3
  import PropTypes from 'prop-types'
5
4
  import { Transition } from 'react-transition-group'
@@ -96,9 +95,10 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
96
95
  },
97
96
  ref,
98
97
  ) => {
99
- const popoverRef = useRef(null)
98
+ const popoverRef = useRef<HTMLDivElement>(null)
100
99
  const togglerRef = useRef(null)
101
100
  const forkedRef = useForkedRef(ref, popoverRef)
101
+ const uID = useRef(`popover${Math.floor(Math.random() * 1_000_000)}`)
102
102
 
103
103
  const { initPopper, destroyPopper } = usePopper()
104
104
  const [_visible, setVisible] = useState(visible)
@@ -133,16 +133,6 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
133
133
  setVisible(visible)
134
134
  }, [visible])
135
135
 
136
- useEffect(() => {
137
- if (_visible && togglerRef.current && popoverRef.current) {
138
- initPopper(togglerRef.current, popoverRef.current, popperConfig)
139
- }
140
-
141
- return () => {
142
- destroyPopper()
143
- }
144
- }, [_visible])
145
-
146
136
  const toggleVisible = (visible: boolean) => {
147
137
  if (visible) {
148
138
  setTimeout(() => setVisible(true), _delay.show)
@@ -155,6 +145,9 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
155
145
  return (
156
146
  <>
157
147
  {React.cloneElement(children as React.ReactElement<any>, {
148
+ ...(_visible && {
149
+ 'aria-describedby': uID.current,
150
+ }),
158
151
  ref: togglerRef,
159
152
  ...((trigger === 'click' || trigger.includes('click')) && {
160
153
  onClick: () => toggleVisible(!_visible),
@@ -173,8 +166,22 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
173
166
  in={_visible}
174
167
  mountOnEnter
175
168
  nodeRef={popoverRef}
176
- onEnter={onShow}
169
+ onEnter={() => {
170
+ if (togglerRef.current && popoverRef.current) {
171
+ initPopper(togglerRef.current, popoverRef.current, popperConfig)
172
+ }
173
+
174
+ onShow
175
+ }}
176
+ onEntering={() => {
177
+ if (togglerRef.current && popoverRef.current) {
178
+ popoverRef.current.style.display = 'initial'
179
+ }
180
+ }}
177
181
  onExit={onHide}
182
+ onExited={() => {
183
+ destroyPopper()
184
+ }}
178
185
  timeout={{
179
186
  enter: 0,
180
187
  exit: popoverRef.current
@@ -194,8 +201,12 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
194
201
  },
195
202
  className,
196
203
  )}
204
+ id={uID.current}
197
205
  ref={forkedRef}
198
206
  role="tooltip"
207
+ style={{
208
+ display: 'none',
209
+ }}
199
210
  {...rest}
200
211
  >
201
212
  <div className="popover-arrow"></div>
@@ -90,9 +90,10 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
90
90
  },
91
91
  ref,
92
92
  ) => {
93
- const tooltipRef = useRef(null)
93
+ const tooltipRef = useRef<HTMLDivElement>(null)
94
94
  const togglerRef = useRef(null)
95
95
  const forkedRef = useForkedRef(ref, tooltipRef)
96
+ const uID = useRef(`tooltip${Math.floor(Math.random() * 1_000_000)}`)
96
97
 
97
98
  const { initPopper, destroyPopper } = usePopper()
98
99
  const [_visible, setVisible] = useState(visible)
@@ -127,16 +128,6 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
127
128
  setVisible(visible)
128
129
  }, [visible])
129
130
 
130
- useEffect(() => {
131
- if (_visible && togglerRef.current && tooltipRef.current) {
132
- initPopper(togglerRef.current, tooltipRef.current, popperConfig)
133
- }
134
-
135
- return () => {
136
- destroyPopper()
137
- }
138
- }, [_visible])
139
-
140
131
  const toggleVisible = (visible: boolean) => {
141
132
  if (visible) {
142
133
  setTimeout(() => setVisible(true), _delay.show)
@@ -149,6 +140,9 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
149
140
  return (
150
141
  <>
151
142
  {React.cloneElement(children as React.ReactElement<any>, {
143
+ ...(_visible && {
144
+ 'aria-describedby': uID.current,
145
+ }),
152
146
  ref: togglerRef,
153
147
  ...((trigger === 'click' || trigger.includes('click')) && {
154
148
  onClick: () => toggleVisible(!_visible),
@@ -167,8 +161,22 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
167
161
  in={_visible}
168
162
  mountOnEnter
169
163
  nodeRef={tooltipRef}
170
- onEnter={onShow}
164
+ onEnter={() => {
165
+ if (togglerRef.current && tooltipRef.current) {
166
+ initPopper(togglerRef.current, tooltipRef.current, popperConfig)
167
+ }
168
+
169
+ onShow
170
+ }}
171
+ onEntering={() => {
172
+ if (togglerRef.current && tooltipRef.current) {
173
+ tooltipRef.current.style.display = 'initial'
174
+ }
175
+ }}
171
176
  onExit={onHide}
177
+ onExited={() => {
178
+ destroyPopper()
179
+ }}
172
180
  timeout={{
173
181
  enter: 0,
174
182
  exit: tooltipRef.current
@@ -188,8 +196,12 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
188
196
  },
189
197
  className,
190
198
  )}
199
+ id={uID.current}
191
200
  ref={forkedRef}
192
201
  role="tooltip"
202
+ style={{
203
+ display: 'none',
204
+ }}
193
205
  {...rest}
194
206
  >
195
207
  <div className="tooltip-arrow"></div>