All worflows are getting triggered

I am using github matrix strategy to deploy github workflows. and I have workflow contains follows:

name: Stop
on:
    
  workflow_dispatch:
    inputs:
          name:
            description: "Enter name type"
            required: true
            default: "fname,wname,lname" 
jobs:
  deploy-name-service:
    name: Deploy to -> ${{ matrix.environment.name }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        environment:
          [
            {
              name: fname,
              myname: "fname"
            },
            {
              name: wname,
              myname: "wname"
            },
            {
              name: lname,
              myname: "lname"
            }
            
         ]
         
         
   
    steps:
       - uses: actions/checkout@v2
         if: contains( github.event.inputs.name, matrix.environment.name )
         
       - name: echo github.event.inputs.name
         run: echo ${{ github.event.inputs }}
         if: contains( github.event.inputs.name, matrix.environment.name 

And when I trigger the github action by selecting one of the input .
action_1

It triggers workflow for that input as well as for other inputs also.
action_2
Is there anyway where we can restrict the workflows to run only on selected input?

if: contains( github.event.inputs.name, matrix.environment.name ) should prevent the steps from being run, but it doesn’t stop the matrix jobs from being run.

You could potentially invert the logic and use the workflow_dispatch input for strategy.matrix.exclude to not run the specified matrix jobs.

Or you need to create the matrix dynamically, using a job that runs before the main job. You will need some (shell) code to construct the matrix based on the workflow_dispatch input, then serializes it to JSON and hand it over to the main job, where you deserialize it with fromJSON(). There is a basic example in the documentation: Context and expression syntax for GitHub Actions - GitHub Docs. Also see How to create dynamic matrix value? and related discussions.