Order as guest checkbox

Hi,
I´m having difficulties understanding how the Checkbox that handles the “order as guest” or “create a account to order” works in shopware 5. 

It removes/adds two attributes of the two HTML inputs for the password and adds/removes a class to the div that both inputs are in. 

It removes/adds required=“required” and aria-required=“true” depending on the checkbox and is–hidden is added to the div to hide or show the inputs.

When I do the same in the browser it doesn’t work. The fields are marked as required.

Can someone explain me how that works ? 
I´m trying to reproduce the same function with a button click.

Regards