Skip to content

Commit

Permalink
Changed implementation to use autofill and not set attribute directly…
Browse files Browse the repository at this point in the history
… in DOM
  • Loading branch information
Thomas-Neuhauser committed Dec 12, 2024
1 parent 9d0e41b commit d07be9e
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions packages/ui-components/src/components/UIComboBox/UIComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,12 @@ export class UIComboBox extends React.Component<UIComboBoxProps, UIComboBoxState
this.onScrollToItem = this.onScrollToItem.bind(this);
this.setFocus = this.setFocus.bind(this);
this.onRenderIcon = this.onRenderIcon.bind(this);
this.updateAriaInvalid = this.updateAriaInvalid.bind(this);

initializeComponentRef(this);

this.state = {};
}

/**
* Called when component did initialize.
*/
componentDidMount(): void {
this.updateAriaInvalid();
}

/**
* Called when component is rerendered.
*/
componentDidUpdate(): void {
this.updateAriaInvalid();
}

/**
*
* @param {UIComboBoxProps} nextProps
Expand All @@ -180,18 +165,6 @@ export class UIComboBox extends React.Component<UIComboBoxProps, UIComboBoxState
return true;
}

/**
* This is a workaround for FluentUI not handling aria-invalid correctly for a ComboBox.
* For the time being we add logic here to set aria-invalid based on the presence of
* an errorMessage.
*/
private updateAriaInvalid(): void {
const htmlInputField = this.comboboxDomRef.current?.getElementsByClassName('ms-ComboBox-Input').item(0);
if (htmlInputField) {
htmlInputField.ariaInvalid = this.props.errorMessage !== undefined ? 'true' : 'false';
}
}

/**
* Updates hidden options.
*
Expand Down Expand Up @@ -720,6 +693,10 @@ export class UIComboBox extends React.Component<UIComboBoxProps, UIComboBoxState
autofill.readOnly = true;
autofill.tabIndex = tabIndex;
}
// This is a workaround for FluentUI not handling aria-invalid correctly for a ComboBox.
// For the time being we add logic here to set aria-invalid based on the presence of
// an errorMessage.
autofill['aria-invalid'] = (this.props.errorMessage !== undefined)
return autofill;
}

Expand Down

0 comments on commit d07be9e

Please sign in to comment.