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: [Chat with BOT] After Opening Chat with Bot screen, focus indicator does not land on Live Chat Tab control #73

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 0 additions & 13 deletions packages/app/client/src/ui/editor/emulator/emulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ export interface EmulatorProps {
}

export class Emulator extends React.Component<EmulatorProps, Record<string, unknown>> {
private restartButtonRef: HTMLButtonElement;

private readonly onVerticalSizeChange = debounce((sizes: SplitterSize[]) => {
this.props.ui = {
...this.props.ui,
Expand All @@ -108,12 +106,6 @@ export class Emulator extends React.Component<EmulatorProps, Record<string, unkn
};
}, 500);

componentDidMount() {
if (this.restartButtonRef) {
this.restartButtonRef.focus();
}
}

componentWillMount() {
window.addEventListener('keydown', this.keyboardEventListener);
}
Expand Down Expand Up @@ -159,7 +151,6 @@ export class Emulator extends React.Component<EmulatorProps, Record<string, unkn
options={[NewUserId, SameUserId]}
onClick={this.onRestartOptionSelected}
onDefaultButtonClick={this.onStartOverClick}
buttonRef={this.setRestartButtonRef}
submenuLabel={isMac() ? 'Restart conversation sub menu' : ''}
/>
<button
Expand Down Expand Up @@ -309,10 +300,6 @@ export class Emulator extends React.Component<EmulatorProps, Record<string, unkn
this.props.restartConversation(documentId, true, false);
};

private setRestartButtonRef = (ref: HTMLButtonElement): void => {
this.restartButtonRef = ref;
};

private readonly keyboardEventListener: EventListener = (event: KeyboardEvent): void => {
if (this.props.activeDocumentId === this.props.documentId) {
// Meta corresponds to 'Command' on Mac
Expand Down
20 changes: 19 additions & 1 deletion packages/app/client/src/ui/shell/mdi/tab/tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface TabState {
}

export class Tab extends React.Component<TabProps, TabState> {
private tabRef: HTMLButtonElement;
constructor(props: TabProps) {
super(props);

Expand All @@ -66,6 +67,12 @@ export class Tab extends React.Component<TabProps, TabState> {
};
}

componentDidMount() {
if (this.tabRef) {
this.tabRef.focus();
}
}

public render() {
const { active, label } = this.props;
const activeClassName = active ? styles.activeEditorTab : '';
Expand All @@ -89,7 +96,14 @@ export class Tab extends React.Component<TabProps, TabState> {
<TruncateText className={styles.truncatedTabText}>{label}</TruncateText>
{this.props.dirty ? <span role="presentation">*</span> : null}
<div className={styles.tabSeparator} role="presentation" />
<div className={styles.tabFocusTarget} role="tab" tabIndex={0} aria-label={`${label}`} aria-selected={active}>
<div
className={styles.tabFocusTarget}
role="tab"
tabIndex={0}
aria-label={`${label}`}
aria-selected={active}
ref={this.setTabRef}
>
&nbsp;
</div>
<button
Expand Down Expand Up @@ -171,4 +185,8 @@ export class Tab extends React.Component<TabProps, TabState> {
return styles.livechat;
}
}

private setTabRef = (ref: HTMLButtonElement): void => {
this.tabRef = ref;
};
}
12 changes: 7 additions & 5 deletions packages/sdk/ui-react/src/widget/splitButton/splitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class SplitButton extends React.Component<SplitButtonProps, SplitButtonSt
}

componentDidMount() {
this.onClickOption(0);
this.onClickOption(0, false);
}

public render(): JSX.Element {
Expand Down Expand Up @@ -158,18 +158,20 @@ export class SplitButton extends React.Component<SplitButtonProps, SplitButtonSt
}
};

private onClickOption = (index: number): void => {
private onClickOption = (index: number, focus: boolean = true): void => {
const { onClick, options = [] } = this.props;
if (onClick && options.length > 0) {
const newValue = options[index] || null;
this.setState({ selected: index });
onClick(newValue);
}
this.hidePanel();
this.hidePanel(focus);
};

private hidePanel = (): void => {
this.caretRef.focus();
private hidePanel = (focus: boolean = true): void => {
if (focus) {
this.caretRef.focus();
}
this.setState({ expanded: false });
};

Expand Down