Skip to content

Commit

Permalink
Skip rendering the whole startAdornment if speech recognition is not …
Browse files Browse the repository at this point in the history
…supported
  • Loading branch information
arminmeh committed Nov 22, 2024
1 parent df05425 commit 45b5ea9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { RecordButton, BrowserSpeechRecognition } from './RecordButton';

type OwnerState = DataGridPremiumProcessedProps;

const supportsSpeechRecognition = !!BrowserSpeechRecognition;

const useUtilityClasses = (ownerState: OwnerState, recording: boolean) => {
const { classes } = ownerState;

Expand Down Expand Up @@ -206,7 +208,7 @@ function GridToolbarPromptControl(props: GridToolbarPromptControlProps) {
}
});

const placeholder = BrowserSpeechRecognition
const placeholder = supportsSpeechRecognition
? apiRef.current.getLocaleText('toolbarPromptControlWithRecordingPlaceholder')
: apiRef.current.getLocaleText('toolbarPromptControlPlaceholder');

Expand All @@ -229,7 +231,7 @@ function GridToolbarPromptControl(props: GridToolbarPromptControlProps) {
error={!!error}
helperText={error}
InputProps={{
startAdornment: (
startAdornment: supportsSpeechRecognition && (
<rootProps.slots.baseInputAdornment position="start">
<RecordButton
className={classes.recordButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,27 @@ function RecordButton(props: RecordButtonProps) {
};

return (
BrowserSpeechRecognition && (
<rootProps.slots.baseTooltip
title={
recording
? apiRef.current.getLocaleText('toolbarPromptControlRecordButtonActiveLabel')
: apiRef.current.getLocaleText('toolbarPromptControlRecordButtonDefaultLabel')
}
>
<div>
<rootProps.slots.baseIconButton
color={recording ? 'primary' : 'default'}
className={className}
disabled={disabled}
onClick={handleClick}
ref={buttonRef}
size="small"
edge="start"
>
<rootProps.slots.toolbarPromptRecordIcon fontSize="small" />
</rootProps.slots.baseIconButton>
</div>
</rootProps.slots.baseTooltip>
)
<rootProps.slots.baseTooltip
title={
recording
? apiRef.current.getLocaleText('toolbarPromptControlRecordButtonActiveLabel')
: apiRef.current.getLocaleText('toolbarPromptControlRecordButtonDefaultLabel')
}
>
<div>
<rootProps.slots.baseIconButton
color={recording ? 'primary' : 'default'}
className={className}
disabled={disabled}
onClick={handleClick}
ref={buttonRef}
size="small"
edge="start"
>
<rootProps.slots.toolbarPromptRecordIcon fontSize="small" />
</rootProps.slots.baseIconButton>
</div>
</rootProps.slots.baseTooltip>
);
}

Expand Down

0 comments on commit 45b5ea9

Please sign in to comment.