Keep sneak held to prevent right-clicking from opening the chest. By holding sneak and right-clicking the chest while you have the hopper selected in your Hotbar, you can place the output of the hopper towards the chest. The chest will be used as the hopper's input if it is placed on top of the hopper.