Skip to content

has-valid-accessibility-state rule doesn't accept functions calls and object properties #107

Closed
@JCMartell

Description

@JCMartell

Hi,

I started using this package and when running it I had some instances where the has-valid-accessibility-state rule gave an error. When looking into some of them, I realized that there's a small issue when you set an accessibilityState property with a function call. For example:

const isFirst : () => boolean = () => { 
    return something === "example";
}

<TouchableOpacity
    accessible
    accessibilityState={{ disabled: isFirst() }}
    disabled={isFirst()}
>
    ...
</TouchableOpacity>

In this example, the has-valid-accessibility-state rule will throw the following error, even though the isFirst function returns a boolean: accessibilityState object: "disabled" value is not a boolean.

Also, I found an instance we I set one of the accessibilityState properties with an object property and got an error. For example:

type MyType = {
    myBool: boolean;
};

const myObj: MyType = {
    myBool: true
};

<TouchableOpacity
    accessible
    accessibilityState={{ checked: myObj.myBool }}
>
    ...
</TouchableOpacity>

The object property is defined as a boolean, but the has-valid-accessibility-state throws the following error:
accessibilityState object: "checked" value is not either a boolean or 'mixed'.

Would it be possible to update the rule so it accepts those situations as well?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions