This is done by utilizing a Balloon type float valve. Its working is thus:
A ball shaped hollow sphere , made of hardened Rubber or Copper alloy sheet is sealed so that water cannot enter it. This is attached to an arm that in turn is attached to the valve or flap.
The valve or flap controls the opening of the pipe through which water flows into the tank/Cistern
Under Empty condition, valve is fully open and balloon is suspended freely.
As water ingresses into the container, the balloon, on account of trapped air and buoyancy, begins to rise / float on the water surface.
Soon the balloon floats high enough so that the arm attached to the Balloon CLOSES the valve and stops water from flowing in.
Thus when water is filled to a certain level, its inflow is stopped by this arrangement.