diff --git a/components/doc/inputtextarea/apidoc.js b/components/doc/inputtextarea/apidoc.js index 8f668217ab..1c1192a83a 100644 --- a/components/doc/inputtextarea/apidoc.js +++ b/components/doc/inputtextarea/apidoc.js @@ -26,6 +26,12 @@ export function ApiDoc(props) { false When present, height of textarea changes as being typed. + + keyfilter + string/regex + null + Format definition of the keys to block. + tooltip any diff --git a/components/doc/inputtextarea/index.js b/components/doc/inputtextarea/index.js deleted file mode 100644 index ba5672cb46..0000000000 --- a/components/doc/inputtextarea/index.js +++ /dev/null @@ -1,277 +0,0 @@ -import React, { memo } from 'react'; -import Link from 'next/link'; -import { TabView, TabPanel } from '../../lib/tabview/TabView'; -import { useLiveEditorTabs } from '../common/liveeditor'; -import { CodeHighlight } from '../common/codehighlight'; -import { DevelopmentSection } from '../common/developmentsection'; - -const InputTextareaDoc = memo(() => { - const sources = { - class: { - tabName: 'Class Source', - content: ` -import React, {Component} from 'react'; -import { InputTextarea } from 'primereact/inputtextarea'; - -export class InputTextareaDemo extends Component { - - constructor(props) { - super(props); - this.state = { - value1: '', - value2: '', - value3: '' - }; - } - - render() { - return ( -
-
-
Basic
- this.setState({value1: e.target.value})} rows={5} cols={30} /> - -
Auto Resize
- this.setState({value2: e.target.value})} rows={5} cols={30} autoResize /> - -
Disabled
- -
-
- ) - } -} - ` - }, - hooks: { - tabName: 'Hooks Source', - content: ` -import React, { useState } from 'react'; -import { InputTextarea } from 'primereact/inputtextarea'; - -const InputTextareaDemo = () => { - const [value1, setValue1] = useState(''); - const [value2, setValue2] = useState(''); - const [value3, setValue3] = useState(''); - - return ( -
-
-
Basic
- setValue1(e.target.value)} rows={5} cols={30} /> - -
Auto Resize
- setValue2(e.target.value)} rows={5} cols={30} autoResize /> - -
Disabled
- -
-
- ) -} - ` - }, - ts: { - tabName: 'TS Source', - content: ` -import React, { useState } from 'react'; -import { InputTextarea } from 'primereact/inputtextarea'; - -const InputTextareaDemo = () => { - const [value1, setValue1] = useState(''); - const [value2, setValue2] = useState(''); - const [value3, setValue3] = useState(''); - - return ( -
-
-
Basic
- setValue1(e.target.value)} rows={5} cols={30} /> - -
Auto Resize
- setValue2(e.target.value)} rows={5} cols={30} autoResize /> - -
Disabled
- -
-
- ) -} - ` - }, - browser: { - tabName: 'Browser Source', - imports: ` - - `, - content: ` -const { useState } = React; -const { InputTextarea } = primereact.inputtextarea; - -const InputTextareaDemo = () => { - const [value1, setValue1] = useState(''); - const [value2, setValue2] = useState(''); - const [value3, setValue3] = useState(''); - - return ( -
-
-
Basic
- setValue1(e.target.value)} rows={5} cols={30} /> - -
Auto Resize
- setValue2(e.target.value)} rows={5} cols={30} autoResize /> - -
Disabled
- -
-
- ) -} - ` - } - }; - - return ( -
- - -
Import via Module
- - {` -import { InputTextarea } from 'primereact/inputtextarea'; -`} - - -
Import via CDN
- - {` - - -`} - - -
Getting Started
-

- Textarea is used as a controlled input with value and onChange properties. -

- - {` - setValue(event.target.value)} /> -`} - - -
AutoResize
-

In auto resize mode, textarea grows instead of displaying a scrollbar.

- - {` - setValue(event.target.value)} autoResize /> -`} - - -
Properties
-

InputTextarea passes any attribute to the underlying textarea element, additional attributes are as follows;

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDefaultDescription
autoResizebooleanfalseWhen present, height of textarea changes as being typed.
tooltipanynullContent of the tooltip.
tooltipOptionsobjectnullConfiguration of the tooltip, refer to the tooltip documentation for more information.
-
- -
Styling
-

- Following is the list of structural style classes, for theming classes visit theming page. -

-
- - - - - - - - - - - - - -
NameElement
p-inputtextareaTextarea element
-
- -
Accessibility
- -
Screen Reader
-

- InputTextarea component renders a native textarea element that implicitly includes any passed prop. Value to describe the component can either be provided via label tag combined with id prop or using{' '} - aria-labelledby, aria-label props. -

- - {` - - - -Address 2 - - - -`} - - -
Keyboard Support
-
- - - - - - - - - - - - - -
KeyFunction
- tab - Moves focus to the input.
-
-
-
Dependencies
-

None.

-
- - {useLiveEditorTabs({ name: 'InputTextareaDemo', sources: sources })} -
-
- ); -}); - -export default InputTextareaDoc; diff --git a/components/doc/inputtextarea/keyfilterdoc.js b/components/doc/inputtextarea/keyfilterdoc.js new file mode 100644 index 0000000000..76d1ecc1eb --- /dev/null +++ b/components/doc/inputtextarea/keyfilterdoc.js @@ -0,0 +1,42 @@ +import Link from 'next/link'; +import { InputTextarea } from '../../lib/inputtextarea/InputTextarea'; +import { DocSectionCode } from '../common/docsectioncode'; +import { DocSectionText } from '../common/docsectiontext'; + +export function KeyFilterDoc(props) { + const code = { + basic: ` + + `, + javascript: ` +import { InputTextarea } from "primereact/inputtextarea"; + +export default function KeyFilterDemo() { + return ( + + ) +} + `, + typescript: ` +import { InputTextarea } from "primereact/inputtextarea"; + +export default function KeyFilterDemo() { + return ( + + ) +} + ` + }; + + return ( + <> + + InputTextarea has built-in key filtering support to block certain keys, refer to keyfilter page for more information. + +
+ +
+ + + ); +} diff --git a/components/lib/inputtext/InputText.js b/components/lib/inputtext/InputText.js index d7b3837447..44268774d2 100644 --- a/components/lib/inputtext/InputText.js +++ b/components/lib/inputtext/InputText.js @@ -7,8 +7,8 @@ export const InputText = React.memo( React.forwardRef((props, ref) => { const elementRef = React.useRef(ref); - const onKeyPress = (event) => { - props.onKeyPress && props.onKeyPress(event); + const onKeyDown = (event) => { + props.onKeyDown && props.onKeyDown(event); if (props.keyfilter) { KeyFilter.onKeyPress(event, props.keyfilter, props.validateOnly); @@ -59,7 +59,7 @@ export const InputText = React.memo( return ( <> - + {hasTooltip && } ); @@ -74,6 +74,6 @@ InputText.defaultProps = { tooltip: null, tooltipOptions: null, onInput: null, - onKeyPress: null, + onKeyDown: null, onPaste: null }; diff --git a/components/lib/inputtextarea/InputTextarea.js b/components/lib/inputtextarea/InputTextarea.js index 4c41b06d8d..f4bc2fd69f 100644 --- a/components/lib/inputtextarea/InputTextarea.js +++ b/components/lib/inputtextarea/InputTextarea.js @@ -1,4 +1,5 @@ import * as React from 'react'; +import { KeyFilter } from '../keyfilter/KeyFilter'; import { Tooltip } from '../tooltip/Tooltip'; import { classNames, DomHandler, ObjectUtils } from '../utils/Utils'; @@ -31,6 +32,22 @@ export const InputTextarea = React.memo( props.onKeyUp && props.onKeyUp(event); }; + const onKeyDown = (event) => { + props.onKeyDown && props.onKeyDown(event); + + if (props.keyfilter) { + KeyFilter.onKeyPress(event, props.keyfilter, props.validateOnly); + } + }; + + const onPaste = (event) => { + props.onPaste && props.onPaste(event); + + if (props.keyfilter) { + KeyFilter.onPaste(event, props.keyfilter, props.validateOnly); + } + }; + const onInput = (event) => { if (props.autoResize) { resize(); @@ -95,7 +112,7 @@ export const InputTextarea = React.memo( return ( <> - + {hasTooltip && } ); @@ -106,7 +123,13 @@ InputTextarea.displayName = 'InputTextarea'; InputTextarea.defaultProps = { __TYPE: 'InputTextarea', autoResize: false, + keyfilter: null, + onBlur: null, + onFocus: null, + onInput: null, + onKeyDown: null, + onKeyUp: null, + onPaste: null, tooltip: null, - tooltipOptions: null, - onInput: null + tooltipOptions: null }; diff --git a/components/lib/inputtextarea/inputtextarea.d.ts b/components/lib/inputtextarea/inputtextarea.d.ts index a45f3b0d44..67f7d04c0b 100644 --- a/components/lib/inputtextarea/inputtextarea.d.ts +++ b/components/lib/inputtextarea/inputtextarea.d.ts @@ -1,9 +1,11 @@ import * as React from 'react'; +import { KeyFilterType } from '../keyfilter'; import TooltipOptions from '../tooltip/tooltipoptions'; export interface InputTextareaProps extends Omit, HTMLTextAreaElement>, 'ref'> { autoResize?: boolean; children?: React.ReactNode; + keyfilter?: KeyFilterType; tooltip?: string; tooltipOptions?: TooltipOptions; } diff --git a/pages/inputtextarea/index.js b/pages/inputtextarea/index.js index 427b6ed2c3..efdbb55235 100644 --- a/pages/inputtextarea/index.js +++ b/pages/inputtextarea/index.js @@ -1,13 +1,14 @@ -import React, { useState } from 'react'; import Head from 'next/head'; -import { DocSections } from '../../components/doc/common/docsections'; +import React from 'react'; import { DocSectionNav } from '../../components/doc/common/docsectionnav'; -import { ImportDoc } from '../../components/doc/inputtextarea/importdoc'; -import { BasicDoc } from '../../components/doc/inputtextarea/basicdoc'; +import { DocSections } from '../../components/doc/common/docsections'; +import { ApiDoc } from '../../components/doc/inputtextarea/apidoc'; import { AutoResizeDoc } from '../../components/doc/inputtextarea/autoresizedoc'; -import { FloatLabelDoc } from '../../components/doc/inputtextarea/floatlabeldoc'; +import { BasicDoc } from '../../components/doc/inputtextarea/basicdoc'; import { DisabledDoc } from '../../components/doc/inputtextarea/disableddoc'; -import { ApiDoc } from '../../components/doc/inputtextarea/apidoc'; +import { FloatLabelDoc } from '../../components/doc/inputtextarea/floatlabeldoc'; +import { ImportDoc } from '../../components/doc/inputtextarea/importdoc'; +import { KeyFilterDoc } from '../../components/doc/inputtextarea/keyfilterdoc'; const InputTextareaDemo = () => { const docs = [ @@ -31,6 +32,11 @@ const InputTextareaDemo = () => { label: 'Float Label', component: FloatLabelDoc }, + { + id: 'keyfilter', + label: 'Key Filter', + component: KeyFilterDoc + }, { id: 'disabled', label: 'Disabled',