The answer is it depends on the type of hardware wallet you’re using and also the type of virus on that device because ideally some other viruses like trackers cannot track your hardware wallet and make you lose your crypto details like keys because hardware wallet blocks the connection between your device and the wallet.
But if the virus in question is a Keylogger then there is going to be a problem when using some hardware wallets, keylogger record your screen and track your entries on keyboard, for hardware wallets that do not require you enter your details using your computer device it is safe but for devices that requires you use the device keyboard to enter information like pins and passphrase it is dangerous.
If I can remember correctly Trezor uses Trezor suit which can expose your entries to the keylogger since it’s on the computer device as such it is not advisable to use this hardware wallet on an infected computer since you don’t even know maybe it is Keylogger viruses