From 25d16bd54fd3e1e2af017a823377a2ed2db196c6 Mon Sep 17 00:00:00 2001 From: melloware Date: Sun, 13 Nov 2022 09:07:28 -0500 Subject: [PATCH 1/2] Ref tests --- components/lib/inputtext/InputText.spec.js | 17 +++++++++++++++++ .../lib/inputtextarea/InputTextarea.spec.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/components/lib/inputtext/InputText.spec.js b/components/lib/inputtext/InputText.spec.js index 7ed7a63aca..2ca9ef6006 100644 --- a/components/lib/inputtext/InputText.spec.js +++ b/components/lib/inputtext/InputText.spec.js @@ -1,6 +1,7 @@ import '@testing-library/jest-dom'; import { fireEvent, render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import * as React from 'react'; import { InputText } from './InputText'; describe('InputText', () => { @@ -109,4 +110,20 @@ describe('InputText', () => { expect(input).toHaveValue(''); expect(pasteOn).toHaveBeenCalledTimes(1); }); + test('when input is using onInput make sure it is called', async () => { + // Arrange + const inputOn = jest.fn(); + const ref = React.createRef(); + const { container } = render(); + const input = container.getElementsByTagName('input')[0]; + + // Act + ref.current.value = 'Jest testing value'; + input.focus(); + await userEvent.paste(' abc'); + + // Assert + expect(input).toHaveValue('Jest testing value abc'); + expect(inputOn).toHaveBeenCalledTimes(1); + }); }); diff --git a/components/lib/inputtextarea/InputTextarea.spec.js b/components/lib/inputtextarea/InputTextarea.spec.js index 6a8882de17..87b11d3862 100644 --- a/components/lib/inputtextarea/InputTextarea.spec.js +++ b/components/lib/inputtextarea/InputTextarea.spec.js @@ -1,6 +1,7 @@ import '@testing-library/jest-dom'; import { fireEvent, render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import * as React from 'react'; import { InputTextarea } from './InputTextarea'; describe('InputTextarea', () => { @@ -121,4 +122,20 @@ describe('InputTextarea', () => { expect(input).toHaveValue(''); expect(pasteOn).toHaveBeenCalledTimes(1); }); + test('when input is using onInput make sure it is called', async () => { + // Arrange + const inputOn = jest.fn(); + const ref = React.createRef(); + const { container } = render(); + const input = container.getElementsByTagName('textarea')[0]; + + // Act + ref.current.value = 'Jest testing value'; + input.focus(); + await userEvent.paste(' abc'); + + // Assert + expect(input).toHaveValue('Jest testing value abc'); + expect(inputOn).toHaveBeenCalledTimes(1); + }); }); From 175d1967b6a0b346094ba4ef868ca19a9ba71359 Mon Sep 17 00:00:00 2001 From: melloware Date: Sun, 13 Nov 2022 09:20:15 -0500 Subject: [PATCH 2/2] Fix #2588: Tooltip add position=mouse --- api-generator/components/tooltip.js | 2 +- components/doc/tooltip/index.js | 94 ++++++++++++---------- components/lib/tooltip/Tooltip.js | 43 +++++----- components/lib/tooltip/tooltipoptions.d.ts | 26 +++--- pages/tooltip/index.js | 11 ++- 5 files changed, 96 insertions(+), 80 deletions(-) diff --git a/api-generator/components/tooltip.js b/api-generator/components/tooltip.js index 39292a1f7a..0e7734ae21 100644 --- a/api-generator/components/tooltip.js +++ b/api-generator/components/tooltip.js @@ -39,7 +39,7 @@ const TooltipProps = [ name: 'position', type: 'string', default: 'right', - description: 'Position of the tooltip, valid values are right, left, top and bottom.' + description: 'Position of the tooltip, valid values are mouse, right, left, top and bottom.' }, { name: 'my', diff --git a/components/doc/tooltip/index.js b/components/doc/tooltip/index.js index cb840189a7..135e1f1ebc 100644 --- a/components/doc/tooltip/index.js +++ b/components/doc/tooltip/index.js @@ -36,18 +36,21 @@ export class TooltipDemo extends Component {
Positions
-
+
-
+
-
+
-
+
+
+ +
Focus and Blur
@@ -155,18 +158,21 @@ const TooltipDemo = () => {
Positions
-
- -
-
- -
-
- -
-
- -
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
Focus and Blur
@@ -273,18 +279,21 @@ const TooltipDemo = () => {
Positions
-
- -
-
- -
-
- -
-
- -
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
Focus and Blur
@@ -401,18 +410,21 @@ const TooltipDemo = () => {
Positions
-
- -
-
- -
-
- -
-
- -
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
Focus and Blur
@@ -661,7 +673,7 @@ import { Tooltip } from 'primereact/tooltip'; position string right - Position of the tooltip, valid values are right, left, top and bottom. + Position of the tooltip, valid values are mouse, right, left, top and bottom. my diff --git a/components/lib/tooltip/Tooltip.js b/components/lib/tooltip/Tooltip.js index 5b1da9bcfe..ba9859b9c9 100644 --- a/components/lib/tooltip/Tooltip.js +++ b/components/lib/tooltip/Tooltip.js @@ -128,7 +128,7 @@ export const Tooltip = React.memo( elementRef.current.style.pointerEvents = 'none'; } - if (isMouseTrack(currentTargetRef.current) && !containerSize.current) { + if ((isMouseTrack(currentTargetRef.current) || position == 'mouse') && !containerSize.current) { containerSize.current = { width: DomHandler.getOuterWidth(elementRef.current), height: DomHandler.getOuterHeight(elementRef.current) @@ -192,7 +192,7 @@ export const Tooltip = React.memo( top = 0, currentPosition = position || positionState; - if (isMouseTrack(target) && coordinate) { + if ((isMouseTrack(target) || currentPosition == 'mouse') && coordinate) { const _containerSize = { width: DomHandler.getOuterWidth(elementRef.current), height: DomHandler.getOuterHeight(elementRef.current) @@ -209,6 +209,7 @@ export const Tooltip = React.memo( top -= _containerSize.height / 2 - mouseTrackTop; break; case 'right': + case 'mouse': left += mouseTrackLeft; top -= _containerSize.height / 2 - mouseTrackTop; break; @@ -491,31 +492,31 @@ export const Tooltip = React.memo( Tooltip.displayName = 'Tooltip'; Tooltip.defaultProps = { __TYPE: 'Tooltip', - id: null, - target: null, - content: null, - disabled: false, - className: null, - style: null, appendTo: null, - position: 'right', - my: null, at: null, - event: null, - showEvent: 'mouseenter', - hideEvent: 'mouseleave', + autoHide: true, autoZIndex: true, baseZIndex: 0, + className: null, + content: null, + disabled: false, + event: null, + hideDelay: 0, + hideEvent: 'mouseleave', + id: null, mouseTrack: false, - mouseTrackTop: 5, mouseTrackLeft: 5, - showDelay: 0, - updateDelay: 0, - hideDelay: 0, - autoHide: true, - showOnDisabled: false, - onBeforeShow: null, + mouseTrackTop: 5, + my: null, onBeforeHide: null, + onBeforeShow: null, + onHide: null, onShow: null, - onHide: null + position: 'right', + showDelay: 0, + showEvent: 'mouseenter', + showOnDisabled: false, + style: null, + target: null, + updateDelay: 0 }; diff --git a/components/lib/tooltip/tooltipoptions.d.ts b/components/lib/tooltip/tooltipoptions.d.ts index 994f7bfc72..f3cefc800b 100644 --- a/components/lib/tooltip/tooltipoptions.d.ts +++ b/components/lib/tooltip/tooltipoptions.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; -type TooltipPositionType = 'top' | 'bottom' | 'left' | 'right'; +type TooltipPositionType = 'top' | 'bottom' | 'left' | 'right' | 'mouse'; type TooltipEventType = 'hover' | 'focus' | 'both'; @@ -12,26 +12,26 @@ interface TooltipEventParams { } export default interface TooltipOptions { - className?: string; - style?: React.CSSProperties; appendTo?: TooltipAppendToType; - position?: TooltipPositionType; - my?: string; at?: string; - event?: TooltipEventType; - showEvent?: string; - hideEvent?: string; + autoHide?: boolean; autoZIndex?: boolean; baseZIndex?: number; + className?: string; + disabled?: boolean; + event?: TooltipEventType; + hideDelay?: number; + hideEvent?: string; mouseTrack?: boolean; - mouseTrackTop?: number; mouseTrackLeft?: number; + mouseTrackTop?: number; + my?: string; + position?: TooltipPositionType; showDelay?: number; - updateDelay?: number; - hideDelay?: number; - autoHide?: boolean; - disabled?: boolean; + showEvent?: string; showOnDisabled?: boolean; + style?: React.CSSProperties; + updateDelay?: number; onBeforeShow?(e: TooltipEventParams): void; onBeforeHide?(e: TooltipEventParams): void; onShow?(e: TooltipEventParams): void; diff --git a/pages/tooltip/index.js b/pages/tooltip/index.js index faa4fe6a52..a0d857c3cd 100644 --- a/pages/tooltip/index.js +++ b/pages/tooltip/index.js @@ -36,18 +36,21 @@ const TooltipDemo = () => {
Positions
-
+
-
+
-
+
-
+
+
+ +
Focus and Blur