Skip to content

Commit

Permalink
Merge pull request #1 from imgiseverything/a11y/add-semantics-to-inpu…
Browse files Browse the repository at this point in the history
…t-button

A11y/add semantics to input button
  • Loading branch information
imgiseverything authored Dec 16, 2024
2 parents dabfb5d + d2af40c commit f79de36
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions component/src/views/chat/input/buttons/camera/cameraButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class CameraButton extends InputButton<Styles> {
private static createButtonElement() {
const buttonElement = document.createElement('div');
buttonElement.classList.add('input-button');
buttonElement.role = 'button';
buttonElement.setAttribute('tabindex', '0');
return buttonElement;
}

Expand Down
3 changes: 2 additions & 1 deletion component/src/views/chat/input/buttons/inputButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
height: 1.65em;
}

.input-button:hover {
.input-button:hover,
.input-button:focus-visible {
background-color: #9c9c9c2e;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class MicrophoneButton extends InputButton<Styles> {
const buttonElement = document.createElement('div');
buttonElement.id = 'microphone-button';
buttonElement.classList.add('input-button');
buttonElement.role = 'button';
buttonElement.setAttribute('tabindex', '0');
return buttonElement;
}

Expand Down
10 changes: 10 additions & 0 deletions component/src/views/chat/input/buttons/submit/submitButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export class SubmitButton extends InputButton<Styles> {
private static createButtonContainerElement() {
const buttonElement = document.createElement('div');
buttonElement.classList.add('input-button');
buttonElement.role = 'button';
buttonElement.setAttribute('tabindex', '0');
return buttonElement;
}

Expand Down Expand Up @@ -220,6 +222,8 @@ export class SubmitButton extends InputButton<Styles> {
private changeToStopIcon() {
if (this._serviceIO.websocket) return; // stop not used for streaming messages in websocket
this.elementRef.classList.remove(SubmitButton.LOADING_CLASS, SubmitButton.DISABLED_CLASS, SubmitButton.SUBMIT_CLASS);
this.elementRef.removeAttribute('aria-busy');
this.elementRef.removeAttribute('aria-disabled');
this.elementRef.replaceChildren(this._innerElements.stop);
this.reapplyStateStyle('stop', ['loading', 'submit']);
this.elementRef.onclick = this.stopStream.bind(this);
Expand All @@ -230,7 +234,9 @@ export class SubmitButton extends InputButton<Styles> {
if (this._serviceIO.websocket) return;
if (!this._isSVGLoadingIconOverriden) this.elementRef.replaceChildren(this._innerElements.loading);
this.elementRef.classList.remove(SubmitButton.SUBMIT_CLASS, SubmitButton.DISABLED_CLASS);
this.elementRef.removeAttribute('aria-disabled');
this.elementRef.classList.add(SubmitButton.LOADING_CLASS);
this.elementRef.setAttribute('aria-busy', 'true');
this.reapplyStateStyle('loading', ['submit']);
this.elementRef.onclick = () => {};
this.status.requestInProgress = true;
Expand All @@ -241,6 +247,8 @@ export class SubmitButton extends InputButton<Styles> {
public changeToSubmitIcon() {
if (this.elementRef.classList.contains(SubmitButton.SUBMIT_CLASS)) return;
this.elementRef.classList.remove(SubmitButton.LOADING_CLASS, SubmitButton.DISABLED_CLASS);
this.elementRef.removeAttribute('aria-busy');
this.elementRef.removeAttribute('aria-disabled');
this.elementRef.classList.add(SubmitButton.SUBMIT_CLASS);
this.elementRef.replaceChildren(this._innerElements.submit);
SubmitButtonStateStyle.resetSubmit(this, this.status.loadingActive);
Expand All @@ -258,7 +266,9 @@ export class SubmitButton extends InputButton<Styles> {
this.changeToSubmitIcon();
} else if (!this.elementRef.classList.contains(SubmitButton.DISABLED_CLASS)) {
this.elementRef.classList.remove(SubmitButton.LOADING_CLASS, SubmitButton.SUBMIT_CLASS);
this.elementRef.removeAttribute('aria-busy');
this.elementRef.classList.add(SubmitButton.DISABLED_CLASS);
this.elementRef.setAttribute('aria-disabled', 'true');
this.elementRef.replaceChildren(this._innerElements.disabled);
this.reapplyStateStyle('disabled', ['submit']);
this.elementRef.onclick = () => {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class UploadFileButton extends InputButton<Styles> {
private static createButtonElement() {
const buttonElement = document.createElement('div');
buttonElement.classList.add('input-button', 'upload-file-button');
buttonElement.role = 'button';
buttonElement.setAttribute('tabindex', '0');
return buttonElement;
}

Expand Down

0 comments on commit f79de36

Please sign in to comment.