Electronic device with magnetic attachment