components icon indicating copy to clipboard operation
components copied to clipboard

[Bug]: loadingText does not display when button is in a loading state

Open Tro95 opened this issue 10 months ago • 3 comments

Browser

Firefox

Package version

3.0.624

React version

18.3.1

Description

The loadingText property of the Button component does not appear to be working as advertised in https://cloudscape.design/components/button?tabId=api. When I have a Button with the loading property set to true, I expect the loadingText string to be the text rendered inside the button, but instead the button continues to show the text rendered from the child component.

Source code

No response

Reproduction

import React from 'react';
import "@cloudscape-design/global-styles/index.css"

import { AppLayout, Button} from '@cloudscape-design/components';

export default function App() {
    return (
        <AppLayout
            content={
                <Button
                    loading={true}
                    loadingText="Is loading"
                >
                    Not loading
                </Button>
            }
            toolsHide={true}
        />
    );
}

Code of Conduct

Tro95 avatar May 01 '24 17:05 Tro95

This prop is only for screen readers.

Specifies the text that screen reader announces when the button is in a loading state.


Edit: Though I doubt changing the button text is recommended by the CS team, you can always change the content of the button yourself when the loading prop is true.

<Button loading={isLoading}>
  {isLoading ? 'Loading' : 'Submit'}
</Button>

drewdh avatar May 02 '24 02:05 drewdh

Thank you, I guess that makes sense.

Is there a reason why the behaviour is limited only to screen readers, as opposed to changing the button text similar to how loadingText works on other components (such as Table or BarChart)? It seems counter-intuitive for the same-named property to work in different ways for different components.

Tro95 avatar May 02 '24 12:05 Tro95

Hello,

Thanks for your question. The loading text is not displayed for buttons because it is assumed that when used on an action button with a label the spinner provides enough information on its own (for sighted customers). For example, if a button "Submit" transitions to a loading state you can change its label to "Submitting" but it is not necessary because the spinner would convey the transition as well. If, however, the loading text does convey additional information you can also update the label or render it alongside the button.

pan-kot avatar May 03 '24 10:05 pan-kot

Closing issue, please let us know if there are any further questions.

gethinwebster avatar May 07 '24 07:05 gethinwebster