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

feat(input): add readonly attribute #619

Merged
merged 2 commits into from
Jun 7, 2023
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
4 changes: 4 additions & 0 deletions src/components/input/bl-input.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ import { extraPadding } from '../../utilities/chromatic-decorators';
disabled: {
control: 'boolean',
},
readonly: {
control: 'boolean',
},
labelFixed: {
control: 'boolean',
},
Expand All @@ -90,6 +93,7 @@ export const SingleInputTemplate = (args) => html`<bl-input
value='${ifDefined(args.value)}'
?required='${args.required}'
?disabled='${args.disabled}'
?readonly='${args.readonly}'
?label-fixed='${args.labelFixed}'
invalid-text='${ifDefined(args.customInvalidText)}'
help-text='${ifDefined(args.helpText)}'
Expand Down
9 changes: 8 additions & 1 deletion src/components/input/bl-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class BlInput extends FormControlMixin(LitElement) {
static get styles(): CSSResultGroup {
return [style];
}
static shadowRootOptions = {...LitElement.shadowRootOptions, delegatesFocus: true};
static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };

static formControlValidators = innerInputValidators;

Expand Down Expand Up @@ -138,6 +138,12 @@ export default class BlInput extends FormControlMixin(LitElement) {
@property({ type: Boolean, reflect: true })
disabled = false;

/**
* Makes the input readonly.
*/
@property({ type: Boolean, reflect: true })
readonly = false;

/**
* Makes label as fixed positioned
*/
Expand Down Expand Up @@ -335,6 +341,7 @@ export default class BlInput extends FormControlMixin(LitElement) {
step="${ifDefined(this.step)}"
?required=${this.required}
?disabled=${this.disabled}
?readonly=${this.readonly}
@change=${this.changeHandler}
@input=${this.inputHandler}
aria-invalid=${this.checkValidity() ? 'false' : 'true'}
Expand Down