| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import * as React from 'react'; | ||
| import styles from '@patternfly/patternfly/components/FormControl/form-control.css'; | ||
| import { css } from '@patternfly/react-styles'; | ||
| import { Omit } from '../../helpers/typeUtils'; | ||
| import { FormEvent } from 'react'; | ||
|
|
||
| export enum TextInputTypes { | ||
| text = 'text', | ||
| date = 'date', | ||
| datetimeLocal = 'datetime-local', | ||
| email = 'email', | ||
| month = 'month', | ||
| number = 'number', | ||
| password = 'password', | ||
| search = 'search', | ||
| tel = 'tel', | ||
| time = 'time', | ||
| url = 'url' | ||
| } | ||
|
|
||
| export interface TextInputProps extends Omit<React.HTMLProps<HTMLInputElement>, 'onChange' | 'disabled'> { | ||
| /** Additional classes added to the TextInput. */ | ||
| className?: string; | ||
| /** Flag to show if the input is disabled. */ | ||
| isDisabled?: boolean; | ||
| /** Flag to show if the input is read only. */ | ||
| isReadOnly?: boolean; | ||
| /** Flag to show if the input is required. */ | ||
| isRequired?: boolean; | ||
| /** Flag to show if the input is valid or invalid. */ | ||
| isValid?: boolean; | ||
| /** A callback for when the input value changes. */ | ||
| onChange?: (value: string, event: React.FormEvent<HTMLInputElement>) => void; | ||
| /** Type that the input accepts. */ | ||
| type?: 'text' | 'date' | 'datetime-local' | 'email' | 'month' | 'number' | 'password' | 'search' | 'tel' | 'time' | 'url'; | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityTo allow use of the enum, I believe you need to add | TextInputTypes
Sorry, something went wrong.
All reactions
|
||
| /** Value of the input. */ | ||
| value?: string | number; | ||
| /** Aria-label. The input requires an associated id or aria-label. */ | ||
| 'aria-label'?: string; | ||
|
Comment thread
rebeccaalpert marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export class TextInput extends React.Component<TextInputProps> { | ||
| static defaultProps = { | ||
|
Comment thread
rebeccaalpert marked this conversation as resolved.
|
||
| 'aria-label': null as string, | ||
| className: '', | ||
| isRequired: false, | ||
| isValid: true, | ||
| isDisabled: false, | ||
| isReadOnly: false, | ||
| type: 'text' | ||
|
Comment thread
rebeccaalpert marked this conversation as resolved.
Comment thread
rebeccaalpert marked this conversation as resolved.
|
||
| } | ||
|
|
||
| constructor(props: TextInputProps) { | ||
| super(props); | ||
| if (!props.id && !props['aria-label'] && !props['aria-labelledby']) { | ||
| // tslint:disable-next-line:no-console | ||
| console.error('Text input:', 'Text input requires either an id or aria-label to be specified'); | ||
|
Comment thread
rebeccaalpert marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| handleChange = (event: React.FormEvent<HTMLInputElement>) => { | ||
| this.props.onChange(event.currentTarget.value, event); | ||
| } | ||
|
|
||
| render() { | ||
| const { className, type, value, onChange, isValid, isReadOnly, isRequired, isDisabled, ...props } = this.props; | ||
| return ( | ||
| <input | ||
| {...props} | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityLet's spread the props at the end to be consistent across components.
Sorry, something went wrong.
All reactions
|
||
| className={css(styles.formControl, className)} | ||
| onChange={this.handleChange} | ||
| type={type} | ||
| value={value} | ||
| aria-invalid={!isValid} | ||
| required={isRequired} | ||
| disabled={isDisabled} | ||
| readOnly={isReadOnly} | ||
| /> | ||
| ); | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './TextInput'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| describe('Text Input Demo Test', () => { | ||
| it('Navigate to demo section', () => { | ||
| cy.visit('http://localhost:3000/'); | ||
| cy.get('#text-input-demo-nav-item-link').click(); | ||
| cy.url().should('eq', 'http://localhost:3000/text-input-demo-nav-link') | ||
| }); | ||
|
|
||
| it('Verify text input', () => { | ||
| cy.get('#text').type('Hello world'); | ||
|
Comment thread
rebeccaalpert marked this conversation as resolved.
|
||
| cy.get('#text').should('have.value', 'Hello world'); | ||
| }); | ||
|
|
||
| it('Verify disabled text input', () => { | ||
| cy.get('#text-disabled').should('be.disabled'); | ||
| }); | ||
|
|
||
| it('Verify read-only input', () => { | ||
| cy.get('#text-read-only').should('have.attr', 'readonly'); | ||
| }); | ||
|
|
||
| it('Verify invalid text input', () => { | ||
| cy.get('#text-invalid').should('have.attr', 'aria-invalid'); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { TextInput, TextInputProps, TextInputTypes } from '@patternfly/react-core'; | ||
| import React, { Component } from 'react'; | ||
|
|
||
| export class TextInputDemo extends Component { | ||
| state = { | ||
| value: '' | ||
| }; | ||
|
|
||
| handleTextInputChange = value => { | ||
| this.setState({ value }); | ||
| }; | ||
|
|
||
| myTextInputProps: TextInputProps = { | ||
| onChange: this.handleTextInputChange, | ||
| }; | ||
|
|
||
| myDisabledTextInputProps: TextInputProps = { | ||
| isDisabled: true, | ||
| value: 'disabled text input example' | ||
| }; | ||
|
|
||
| myReadOnlyTextInputProps: TextInputProps = { | ||
| isReadOnly: true, | ||
| value: 'read only text input example' | ||
| }; | ||
|
|
||
| myValidTextInputProps: TextInputProps = { | ||
| isValid: false | ||
| }; | ||
|
|
||
| render() { | ||
| return ( | ||
| <React.Fragment> | ||
| <TextInput id="text" onChange={this.myTextInputProps.onChange} /> | ||
| <TextInput id="text-disabled" isDisabled={this.myDisabledTextInputProps.isDisabled} value={this.myDisabledTextInputProps.value} /> | ||
| <TextInput id="text-read-only" isReadOnly={this.myReadOnlyTextInputProps.isReadOnly} value={this.myReadOnlyTextInputProps.value} /> | ||
| <TextInput id="text-invalid" isValid={this.myValidTextInputProps.isValid} /> | ||
| </React.Fragment> | ||
| ); | ||
| } | ||
| } |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityChange the extension on this file to .tsx
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.