A keyway that is wider than the bore in a part is impossible. It would no longer be a keyway because it could not lock into the diameter of the shaft. The maximum keyway width is 1/2 the bore diameter.
The keyway length is different. For square keys the key is often longer than the part being mounted to the shaft. This allows for adjustment in position while retaining engagement along the full width of the part. The keyway is then cut even longer to allow variability in the keys position and length. Especially for longer keys they are often cut from a length of key stock and do not require precision. Remember this is only for square keys.
Sometimes the key used is not as long as the part it will be engaging. This is usually done for clearance issues. Keys are very strong and usually do not need full engagement with the entire width of the part mating to the shaft. It really depends on your power transmission requirements.