Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3575: InputTextArea add KeyFilter #3576

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/doc/inputtextarea/apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export function ApiDoc(props) {
<td>false</td>
<td>When present, height of textarea changes as being typed.</td>
</tr>
<tr>
<td>keyfilter</td>
<td>string/regex</td>
<td>null</td>
<td>Format definition of the keys to block.</td>
</tr>
<tr>
<td>tooltip</td>
<td>any</td>
Expand Down
277 changes: 0 additions & 277 deletions components/doc/inputtextarea/index.js

This file was deleted.

42 changes: 42 additions & 0 deletions components/doc/inputtextarea/keyfilterdoc.js
Original file line number Diff line number Diff line change
@@ -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: `
<InputTextarea keyfilter="int" placeholder="Integers" />
`,
javascript: `
import { InputTextarea } from "primereact/inputtextarea";

export default function KeyFilterDemo() {
return (
<InputTextarea keyfilter="int" placeholder="Integers" rows={2} cols={30}/>
)
}
`,
typescript: `
import { InputTextarea } from "primereact/inputtextarea";

export default function KeyFilterDemo() {
return (
<InputTextarea keyfilter="int" placeholder="Integers" rows={2} cols={30}/>
)
}
`
};

return (
<>
<DocSectionText {...props}>
InputTextarea has built-in key filtering support to block certain keys, refer to <Link href="/keyfilter">keyfilter</Link> page for more information.
</DocSectionText>
<div className="card flex justify-content-center">
<InputTextarea keyfilter="int" placeholder="Integers" rows={2} cols={30} />
</div>
<DocSectionCode code={code} />
</>
);
}
8 changes: 4 additions & 4 deletions components/lib/inputtext/InputText.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -59,7 +59,7 @@ export const InputText = React.memo(

return (
<>
<input ref={elementRef} {...otherProps} className={className} onInput={onInput} onKeyPress={onKeyPress} onPaste={onPaste} />
<input ref={elementRef} {...otherProps} className={className} onInput={onInput} onKeyDown={onKeyDown} onPaste={onPaste} />
{hasTooltip && <Tooltip target={elementRef} content={props.tooltip} {...props.tooltipOptions} />}
</>
);
Expand All @@ -74,6 +74,6 @@ InputText.defaultProps = {
tooltip: null,
tooltipOptions: null,
onInput: null,
onKeyPress: null,
onKeyDown: null,
onPaste: null
};
Loading